Class: Plangrade::Resources::Company
- Defined in:
- lib/plangrade/resources/company.rb
Instance Attribute Summary collapse
-
#ein ⇒ Object
readonly
Returns the value of attribute ein.
-
#grade ⇒ Object
readonly
Returns the value of attribute grade.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Company
constructor
A new instance of Company.
- #update!(params) ⇒ Object
Methods inherited from Base
#api_handler, #base_name, base_name, #changes, #delete!, fetch, identity_map, #load!, #loaded?, model_attributes, #modified?, #new_record?, #persisted?, #reload!, #save
Methods included from ApiHandler
#api_handler, #establish_api_handler
Constructor Details
#initialize(attributes) ⇒ Company
Returns a new instance of Company.
6 7 8 9 10 11 |
# File 'lib/plangrade/resources/company.rb', line 6 def initialize(attributes) @id = attributes["id"] @name = attributes["name"] @ein = attributes["ein"] @grade = attributes["grade"] end |
Instance Attribute Details
#ein ⇒ Object (readonly)
Returns the value of attribute ein.
4 5 6 |
# File 'lib/plangrade/resources/company.rb', line 4 def ein @ein end |
#grade ⇒ Object (readonly)
Returns the value of attribute grade.
4 5 6 |
# File 'lib/plangrade/resources/company.rb', line 4 def grade @grade end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/plangrade/resources/company.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/plangrade/resources/company.rb', line 4 def name @name end |
Class Method Details
.all(*opts) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/plangrade/resources/company.rb', line 26 def self.all(*opts) if opts && opts != nil && opts != {} result = api_handler.all_companies(opts) else result = api_handler.all_companies end parsed_result = JSON.parse(result) raise parsed_result["companies"].to_yaml companies.map { |attributes| new(attributes) } end |
.create(ein, name) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/plangrade/resources/company.rb', line 13 def self.create(ein, name) result = api_handler.create_company(:ein => ein, :name => name) return nil unless result.created? id = result.headers[:location].split('/').last.to_i new(:id => id) end |
.get(id) ⇒ Object
20 21 22 23 24 |
# File 'lib/plangrade/resources/company.rb', line 20 def self.get(id) result = api_handler.get_company(id) return nil unless result.success? new(result.body[:company]) end |
Instance Method Details
#update!(params) ⇒ Object
37 38 39 |
# File 'lib/plangrade/resources/company.rb', line 37 def update!(params) api_handler.update_company(@id, params) end |