|
| 1 | +# This class represents an address in Rosette API. |
| 2 | +class AddressParameter |
| 3 | + # house (optional) |
| 4 | + attr_accessor :house |
| 5 | + # houseNumber (optional) |
| 6 | + attr_accessor :houseNumber |
| 7 | + # road (optional) |
| 8 | + attr_accessor :road |
| 9 | + # unit (optional) |
| 10 | + attr_accessor :unit |
| 11 | + # level (optional) |
| 12 | + attr_accessor :level |
| 13 | + # staircase (optional) |
| 14 | + attr_accessor :staircase |
| 15 | + # entrance (optional) |
| 16 | + attr_accessor :entrance |
| 17 | + # suburb (optional) |
| 18 | + attr_accessor :suburb |
| 19 | + # cityDistrict (optional) |
| 20 | + attr_accessor :cityDistrict |
| 21 | + # city (optional) |
| 22 | + attr_accessor :city |
| 23 | + # island (optional) |
| 24 | + attr_accessor :island |
| 25 | + # stateDistrict (optional) |
| 26 | + attr_accessor :stateDistrict |
| 27 | + # state (optional) |
| 28 | + attr_accessor :state |
| 29 | + # countryRegion (optional) |
| 30 | + attr_accessor :countryRegion |
| 31 | + # country (optional) |
| 32 | + attr_accessor :country |
| 33 | + # worldRegion (optional) |
| 34 | + attr_accessor :worldRegion |
| 35 | + # postCode (optional) |
| 36 | + attr_accessor :postCode |
| 37 | + # poBox (optional) |
| 38 | + attr_accessor :poBox |
| 39 | + |
| 40 | + def initialize(options = {}) #:notnew: |
| 41 | + options = { |
| 42 | + house: nil, |
| 43 | + houseNumber: nil, |
| 44 | + road: nil, |
| 45 | + unit: nil, |
| 46 | + level: nil, |
| 47 | + staircase: nil, |
| 48 | + entrance: nil, |
| 49 | + suburb: nil, |
| 50 | + cityDistrict: nil, |
| 51 | + city: nil, |
| 52 | + island: nil, |
| 53 | + stateDistrict: nil, |
| 54 | + state: nil, |
| 55 | + countryRegion: nil, |
| 56 | + country: nil, |
| 57 | + worldRegion: nil, |
| 58 | + postCode: nil, |
| 59 | + poBox: nil |
| 60 | + }.update options |
| 61 | + @house = options[:house] |
| 62 | + @houseNumber = options[:houseNumber] |
| 63 | + @road = options[:road] |
| 64 | + @unit = options[:unit] |
| 65 | + @level = options[:level] |
| 66 | + @staircase = options[:staircase] |
| 67 | + @entrance = options[:entrance] |
| 68 | + @suburb = options[:suburb] |
| 69 | + @cityDistrict = options[:cityDistrict] |
| 70 | + @city = options[:city] |
| 71 | + @island = options[:island] |
| 72 | + @stateDistrict = options[:stateDistrict] |
| 73 | + @state = options[:state] |
| 74 | + @countryRegion = options[:countryRegion] |
| 75 | + @country = options[:country] |
| 76 | + @worldRegion = options[:worldRegion] |
| 77 | + @postCode = options[:postCode] |
| 78 | + @poBox = options[:poBox] |
| 79 | + end |
| 80 | + |
| 81 | + # Converts this class to Hash with its keys in lower CamelCase. |
| 82 | + # |
| 83 | + # Returns the new Hash. |
| 84 | + def load_param |
| 85 | + to_hash.select { |_key, value| value } |
| 86 | + .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } |
| 87 | + .to_h |
| 88 | + end |
| 89 | + |
| 90 | + # Converts this class to Hash. |
| 91 | + # |
| 92 | + # Returns the new Hash. |
| 93 | + def to_hash |
| 94 | + { |
| 95 | + house: @house, |
| 96 | + houseNumber: @houseNumber, |
| 97 | + road: @road, |
| 98 | + unit: @unit, |
| 99 | + level: @level, |
| 100 | + staircase: @staircase, |
| 101 | + entrance: @entrance, |
| 102 | + suburb: @suburb, |
| 103 | + cityDistrict: @cityDistrict, |
| 104 | + city: @city, |
| 105 | + island: @island, |
| 106 | + stateDistrict: @stateDistrict, |
| 107 | + state: @state, |
| 108 | + countryRegion: @countryRegion, |
| 109 | + country: @country, |
| 110 | + worldRegion: @worldRegion, |
| 111 | + postCode: @postCode, |
| 112 | + poBox: @poBox |
| 113 | + } |
| 114 | + end |
| 115 | +end |
0 commit comments