Class: RelatonBib::Place::RegionType
Constant Summary collapse
- STATES =
{ "AK" => "Alaska", "AL" => "Alabama", "AR" => "Arkansas", "AZ" => "Arizona", "CA" => "California", "CO" => "Colorado", "CT" => "Connecticut", "DC" => "District Of Columbia", "DE" => "Delaware", "FL" => "Florida", "GA" => "Georgia", "GU" => "Guam", "HI" => "Hawaii", "IA" => "Iowa", "ID" => "Idaho", "IL" => "Illinois", "IN" => "Indiana", "KS" => "Kansas", "KY" => "Kentucky", "LA" => "Louisiana", "MA" => "Massachusetts", "MD" => "Maryland", "ME" => "Maine", "MI" => "Michigan", "MN" => "Minnesota", "MO" => "Missouri", "MS" => "Mississippi", "MT" => "Montana", "NC" => "North Carolina", "ND" => "North Dakota", "NE" => "Nebraska", "NH" => "New Hampshire", "NJ" => "New Jersey", "NM" => "New Mexico", "NV" => "Nevada", "NY" => "New York", "OH" => "Ohio", "OK" => "Oklahoma", "OR" => "Oregon", "PA" => "Pennsylvania", "PR" => "Puerto Rico", "RI" => "Rhode Island", "SC" => "South Carolina", "SD" => "South Dakota", "TN" => "Tennessee", "TX" => "Texas", "UT" => "Utah", "VA" => "Virginia", "VI" => "Virgin Islands", "VT" => "Vermont", "WA" => "Washington", "WI" => "Wisconsin", "WV" => "West Virginia", "WY" => "Wyoming", }.freeze
Instance Attribute Summary collapse
-
#iso ⇒ Strign?
readonly
ISO code of region.
-
#name ⇒ Strign
readonly
Name of region.
- #recommended ⇒ Boolean? readonly
Instance Method Summary collapse
-
#initialize(name: nil, iso: nil, recommended: nil) ⇒ RegionType
constructor
Initialize region type.
-
#to_asciibib(pref, count = 1) ⇒ String
Render region type as AsciiBib.
-
#to_hash ⇒ Hash
Render region type as Hash.
-
#to_xml(builder) ⇒ Object
Render region type as XML.
Constructor Details
#initialize(name: nil, iso: nil, recommended: nil) ⇒ RegionType
Initialize region type. Name or valid US state ISO code should be provided.
153 154 155 156 157 158 159 160 161 |
# File 'lib/relaton_bib/place.rb', line 153 def initialize(name: nil, iso: nil, recommended: nil) unless name || STATES.key?(iso&.upcase) raise ArgumentError, "`name` or valid US state ISO code should be provided" end @name = name || STATES[iso&.upcase] @iso = iso @recommended = recommended end |
Instance Attribute Details
#iso ⇒ Strign? (readonly)
Returns ISO code of region.
141 142 143 |
# File 'lib/relaton_bib/place.rb', line 141 def iso @iso end |
#name ⇒ Strign (readonly)
Returns name of region.
138 139 140 |
# File 'lib/relaton_bib/place.rb', line 138 def name @name end |
#recommended ⇒ Boolean? (readonly)
144 145 146 |
# File 'lib/relaton_bib/place.rb', line 144 def recommended @recommended end |
Instance Method Details
#to_asciibib(pref, count = 1) ⇒ String
Render region type as AsciiBib.
194 195 196 197 198 199 200 |
# File 'lib/relaton_bib/place.rb', line 194 def to_asciibib(pref, count = 1) # rubocop:disable Metrics/AbcSize out = count > 1 ? "#{pref}::\n" : "" out += "#{pref}.name:: #{name}\n" out += "#{pref}.iso:: #{iso}\n" if iso out += "#{pref}.recommended:: #{recommended}\n" if recommended out end |
#to_hash ⇒ Hash
Render region type as Hash.
179 180 181 182 183 184 |
# File 'lib/relaton_bib/place.rb', line 179 def to_hash hash = { "name" => name } hash["iso"] = iso if iso hash["recommended"] = recommended unless recommended.nil? hash end |
#to_xml(builder) ⇒ Object
Render region type as XML.
168 169 170 171 172 |
# File 'lib/relaton_bib/place.rb', line 168 def to_xml(builder) builder.parent["iso"] = iso if iso builder.parent["recommended"] = recommended.to_s unless recommended.nil? builder.text name end |