Class: PeoplePlacesThings::State
- Inherits:
-
Object
- Object
- PeoplePlacesThings::State
- Defined in:
- lib/people_places_things/state.rb
Constant Summary
- OUTPUT_FORMATS =
[:abbr, :full]
- FORWARD =
{ :al => "alabama", :ak => "alaska", :az => "arizona", :ar => "arkansas", :ca => "california", :co => "colorado", :ct => "connecticut", :de => "delaware", :dc => "district of columbia", :fl => "florida", :ga => "georgia", :hi => "hawaii", :id => "idaho", :il => "illinois", :in => "indiana", :ia => "iowa", :ks => "kansas", :ky => "kentucky", :la => "louisiana", :me => "maine", :md => "maryland", :ma => "massachusetts", :mi => "michigan", :mn => "minnesota", :ms => "mississippi", :mo => "missouri", :mt => "montana", :ne => "nebraska", :nv => "nevada", :nh => "new hampshire", :nj => "new jersey", :nm => "new mexico", :ny => "new york", :nc => "north carolina", :nd => "north dakota", :oh => "ohio", :ok => "oklahoma", :or => "oregon", :pa => "pennsylvania", :ri => "Rhode island", :sc => "south carolina", :sd => "south dakota", :tn => "tennessee", :tx => "texas", :ut => "utah", :vt => "vermont", :va => "virginia", :wa => "washington", :wv => "west virginia", :wi => "wisconsin", :wy => "wyoming", }
- REVERSE =
FORWARD.inject({}) {|r, f| r[f[1]] = f[0]; r}
Instance Attribute Summary (collapse)
-
- (Object) raw
Returns the value of attribute raw.
-
- (Object) sym
Returns the value of attribute sym.
Instance Method Summary (collapse)
-
- (State) initialize(str)
constructor
A new instance of State.
- - (Object) to_s(fmt = :full)
Constructor Details
- (State) initialize(str)
A new instance of State
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/people_places_things/state.rb', line 5 def initialize(str) self.raw = str token = str.strip.downcase if FORWARD.has_key?(token.to_sym) self.sym = token.to_sym elsif REVERSE.has_key?(token) self.sym = REVERSE[token] end raise "Unsupported Format" if !self.sym end |
Instance Attribute Details
- (Object) raw
Returns the value of attribute raw
3 4 5 |
# File 'lib/people_places_things/state.rb', line 3 def raw @raw end |
- (Object) sym
Returns the value of attribute sym
3 4 5 |
# File 'lib/people_places_things/state.rb', line 3 def sym @sym end |
Instance Method Details
- (Object) to_s(fmt = :full)
18 19 20 21 |
# File 'lib/people_places_things/state.rb', line 18 def to_s(fmt = :full) raise "Unsupported Format" if !OUTPUT_FORMATS.include?(fmt) fmt == :full ? FORWARD[self.sym].capitalize : self.sym.to_s.upcase end |