Class: Nanowrimo::Core
- Inherits:
-
Object
- Object
- Nanowrimo::Core
- Defined in:
- lib/nanowrimo/core.rb
Overview
Core load methods
Instance Attribute Summary collapse
-
#error ⇒ Object
attribute for storing error message returned by WCAPI on any response.
Instance Method Summary collapse
-
#has_error? ⇒ Boolean
Tells us if the current object has any errors from the WCAPI.
-
#load(options = {}) ⇒ Object
Returns the values for all attributes for a given WCAPI type.
-
#load_history(options = {}) ⇒ Object
Returns the values for all attributes for a given WCAPI type’s history.
Instance Attribute Details
#error ⇒ Object
attribute for storing error message returned by WCAPI on any response.
7 8 9 |
# File 'lib/nanowrimo/core.rb', line 7 def error @error end |
Instance Method Details
#has_error? ⇒ Boolean
Tells us if the current object has any errors from the WCAPI
36 37 38 |
# File 'lib/nanowrimo/core.rb', line 36 def has_error? !error.nil? end |
#load(options = {}) ⇒ Object
Returns the values for all attributes for a given WCAPI type
Options:
-
:force - if set to true, will force Nanowrimo data to be pulled from the WCAPI and ignore cache data. not really recommended for bandwidth reasons.
14 15 16 17 18 19 20 21 |
# File 'lib/nanowrimo/core.rb', line 14 def load(={}) attribs = Nanowrimo.parse(load_field,id,self.class::FIELDS,).first self.error = attribs[:error] self.class::FIELDS.each do |attrib| self.send(:"#{attrib}=", attribs[attrib.intern]) end end |
#load_history(options = {}) ⇒ Object
Returns the values for all attributes for a given WCAPI type’s history
Options:
-
:force - if set to true, will force Nanowrimo data to be pulled from the WCAPI and ignore cache data. not really recommended for bandwidth reasons.
28 29 30 31 32 33 |
# File 'lib/nanowrimo/core.rb', line 28 def load_history(={}) self.history = Nanowrimo.parse(load_history_field,id,self.class::HISTORY_FIELDS,) if maybe_error = self.history.first self.error = maybe_error[:error] end end |