Last active
October 30, 2016 16:32
-
-
Save lbvf50mobile/b15d8f931f9d5f0eef1a0c0e5b5bad78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hash = { | |
:text_data => "data", | |
:name => "name", | |
:from_address_select => " name from address slect", | |
:from_name => "name from name ", | |
:from_line1 => "name from line 1 ", | |
:from_line2 => "name from line 2 ", | |
:from_city_name => "name city name " , | |
:from_state_name => "name from state name ", | |
:from_zip => "name from zip", | |
:from_country => "name from country" , | |
:to_address_select => "name to address select", | |
:to_name => "name to name n", | |
:to_line1 => "name ine1 ", | |
:to_line2 => "name line 2", | |
:to_city_name => "name to city name", | |
:to_state_name => "name to state name" , | |
:to_zip => "name to zip ", | |
:to_country => "name to country" | |
} | |
puts "only inject"; | |
# select, cut prefix, strip | |
# :from_zip => " 78 " convert to :zip => "78"" | |
cut_subarray = lambda{|prefix| | |
hash | |
.inject({}){|x,(k,v)| x[k.to_s.sub(prefix,"").to_sym] = v.strip if k.to_s.start_with?(prefix); x} # remove prefix and strip value | |
} | |
from = cut_subarray.call("from_") | |
to = cut_subarray.call("to_") | |
puts from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment