Class: AbrLookup::Lookup
- Inherits:
-
Object
- Object
- AbrLookup::Lookup
- Includes:
- ActiveModel::Conversion, ActiveModel::Naming, ActiveModel::Serializers::JSON, ActiveModel::Validations
- Defined in:
- lib/abr_lookup/lookup.rb
Constant Summary collapse
- ATTRIBUTES =
[:abn, :current, :effective_from, :effective_to, :entity_status, :entity_type, :entity_type_description, :given_name, :family_name, :trading_name, :state_code, :postcode]
Instance Attribute Summary collapse
-
#lookup_number ⇒ Object
readonly
Returns the value of attribute lookup_number.
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
- #attributes ⇒ Object
-
#initialize(lookup_number) ⇒ Lookup
constructor
A new instance of Lookup.
- #lookup_abn! ⇒ Object
Constructor Details
#initialize(lookup_number) ⇒ Lookup
Returns a new instance of Lookup.
17 18 19 |
# File 'lib/abr_lookup/lookup.rb', line 17 def initialize(lookup_number) @lookup_number = lookup_number.to_s.gsub(/([^\w]|_)/, '') end |
Instance Attribute Details
#lookup_number ⇒ Object (readonly)
Returns the value of attribute lookup_number.
14 15 16 |
# File 'lib/abr_lookup/lookup.rb', line 14 def lookup_number @lookup_number end |
Instance Method Details
#as_json(*args) ⇒ Object
31 32 33 |
# File 'lib/abr_lookup/lookup.rb', line 31 def as_json(*args) attributes.stringify_keys end |
#attributes ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/abr_lookup/lookup.rb', line 21 def attributes attrs = {:lookup_number => lookup_number} if errors.present? attrs[:errors] = errors..join(", ") else ATTRIBUTES.inject(attrs){|hash, attr| hash[attr] = send(attr) if send(attr).present?; hash } end attrs end |
#lookup_abn! ⇒ Object
35 36 37 38 |
# File 'lib/abr_lookup/lookup.rb', line 35 def lookup_abn! parse_abn_response(perform_abn_lookup) self end |