Class: Harvest::BaseModel
- Inherits:
-
Object
- Object
- Harvest::BaseModel
- Defined in:
- lib/harvest/base_model.rb
Overview
The parent class of all Harvest models. Contains useful inheritable methods
Direct Known Subclasses
Client, Contact, Expense, ExpenseCategory, Project, RateLimitStatus, Task, TaskAssignment, TimeEntry, User, UserAssignment
Class Method Summary collapse
-
.api_path(path = nil) ⇒ void
This sets the API path so the API collections can use them in an agnostic way.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Checks the equality of another model based on the id.
-
#attributes=(attributes) ⇒ void
Given a hash, sets the corresponding attributes.
-
#initialize(attributes = {}) ⇒ BaseModel
constructor
Initializes the model.
-
#to_i ⇒ Fixnum
Returns the id of the model.
-
#to_xml ⇒ String
Builds the XML of the model.
Constructor Details
#initialize(attributes = {}) ⇒ BaseModel
10 11 12 |
# File 'lib/harvest/base_model.rb', line 10 def initialize(attributes = {}) self.attributes = attributes end |
Class Method Details
.api_path(path = nil) ⇒ void
This method returns an undefined value.
This sets the API path so the API collections can use them in an agnostic way
68 69 70 |
# File 'lib/harvest/base_model.rb', line 68 def api_path(path = nil) @path ||= path end |
Instance Method Details
#==(other) ⇒ Boolean
38 39 40 |
# File 'lib/harvest/base_model.rb', line 38 def ==(other) id == other.id end |
#attributes=(attributes) ⇒ void
23 24 25 |
# File 'lib/harvest/base_model.rb', line 23 def attributes=(attributes) attributes.each {|k,v| send("#{k}=", v)} end |
#to_i ⇒ Fixnum
49 50 51 |
# File 'lib/harvest/base_model.rb', line 49 def to_i id end |
#to_xml ⇒ String
Builds the XML of the model. Primarily used to interact with the Harvest API.
56 57 58 59 60 61 62 63 |
# File 'lib/harvest/base_model.rb', line 56 def to_xml builder = Builder::XmlMarkup.new builder.tag!(self.class.tag_name) do |c| self.class.elements.each do |f| c.tag!(f.tag, send(f.name)) if send(f.name) end end end |