Cleaner way?

I'll first admit this is a lot cleaner and more succinct than my first
pass of it... but well
Is there a way to make this case and send block clearer and cleaner?

Thanks,
         Kyle

def getProperties(type=:textField)

    logWarning("Please use a symbol, not a string for :#{type.to_s}")
unless type.is_a?Symbol

    converter = case type.to_sym
      when :textField,:text_field then "clone"
      when :text,:t,:value then "value"
      when :html then "html"
      else logError("I'm not familiar with :#{type.to_s}, please try
another type.")
    end

    {:name=>@ie.text_field(:id,/EnvironmentTextEdit/).send(converter),
    :start=>@ie.text_field(:id,/StartYearEdit/).send(converter),
    :years=>@ie.text_field(:id,/NumberOfYearsEdit/).send(converter)}
  end

I recently upgraded rails from 1.2.2 to 1.2.3 with (I believe) this command:

gem install rails --system

Somehow this has caused gem to ignore most of my previously installed gems.

THe directory /usr/local/lib/ruby/gems/1.8/gems contains:

RedCloth-3.0.4 actionwebservice-1.1.2 acts_as_searchable-0.1.0 mongrel-0.3.13.3 rails-1.1.2 sources-0.0.1
actionmailer-1.2.1 actionwebservice-1.1.4 capistrano-1.1.0 mongrel_cluster-0.2.0 rails-1.1.4
actionmailer-1.2.3 activerecord-1.14.2 daemons-1.0.1 needle-1.3.0 rake-0.7.1
actionpack-1.12.1 activerecord-1.14.3 fixrbconfig-1.2 net-sftp-1.1.0 rcss-0.3.1
actionpack-1.12.3 activesupport-1.3.1 gem_plugin-0.2.1 net-ssh-1.0.9 rmagick-1.13.0

However, gem list only shows these:

*** LOCAL GEMS ***

actionmailer (1.3.3)

actionpack (1.13.3)

actionwebservice (1.2.3)

activerecord (1.15.3)

activesupport (1.4.2)

hpricot (0.6)

rails (1.2.3)

rake (0.7.3)

rfacebook (0.7.1)

sources (0.0.1)

It was a huge hassle to get some of these installed on OSX (like rmagick) and I'd rather not have to re-do them.

How can I fix this?

THanks

How about

MAP={
  :text_field => "clone",
  :textField => "clone",
  :text => "value",
  :t => "value",
  :value => "value",
  :html => "html"
}

def get_properties(type=:text_field)
  logWarning("Please use a symbol, not a string for :#{type.to_s}")
unless Symbol === type

  converter = MAP[:type] or
    logError("I'm not familiar with :#{type.to_s}, please try another type.")

  {
    :name=>@ie.text_field(:id,/EnvironmentTextEdit/).send(converter),
    :start=>@ie.text_field(:id,/StartYearEdit/).send(converter),
    :years=>@ie.text_field(:id,/NumberOfYearsEdit/).send(converter)
  }
end

Kind regards

robert

···

2007/8/3, Kyle Schmitt <kyleaschmitt@gmail.com>:

I'll first admit this is a lot cleaner and more succinct than my first
pass of it... but well
Is there a way to make this case and send block clearer and cleaner?

Thanks,
         Kyle

def getProperties(type=:textField)

    logWarning("Please use a symbol, not a string for :#{type.to_s}")
unless type.is_a?Symbol

    converter = case type.to_sym
      when :textField,:text_field then "clone"
      when :text,:t,:value then "value"
      when :html then "html"
      else logError("I'm not familiar with :#{type.to_s}, please try
another type.")
    end

    {:name=>@ie.text_field(:id,/EnvironmentTextEdit/).send(converter),
    :start=>@ie.text_field(:id,/StartYearEdit/).send(converter),
    :years=>@ie.text_field(:id,/NumberOfYearsEdit/).send(converter)}
  end

Kyle Schmitt schrieb:

I'll first admit this is a lot cleaner and more succinct than my first
pass of it... but well
Is there a way to make this case and send block clearer and cleaner?

I would only resort to #send and friends if neccessarity occurs:

···

-------------------------------------------------------------------
def convert value, type
  case type.to_sym
    when :textField,:text_field then value.clone
    when :text,:t,:value then value.value
    when :html then value.html
    else value
  end
end

def getProperties type = :textField
  {
    :name => convert(@ie.text_field(:id, /EnvironmentTextEdit/), type),
    :start => convert(@ie.text_field(:id, /StartYearEdit/), type),
    :years => convert(@ie.text_field(:id, /NumberOfYearsEdit/), type)
  }
end
-------------------------------------------------------------------

thats much more pleasing to my eye, but YMMV

cheers

Simon

I'm not sure, but I'd start here:

http://armyofevilrobots.com/node/418

By the way, I don't actually see a --system option on install in gem help.

···

On 8/2/07, Peter Brown <peter@flippyhead.com> wrote:

I recently upgraded rails from 1.2.2 to 1.2.3 with (I believe) this
command:

gem install rails --system

Somehow this has caused gem to ignore most of my previously installed
gems.

--
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org