Class: FBGraph::Result
- Inherits:
-
Object
- Object
- FBGraph::Result
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/fbgraph/result.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#params ⇒ Object
Returns the value of attribute params.
-
#unparsed ⇒ Object
Returns the value of attribute unparsed.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Implement Comparable.
-
#each(&block) ⇒ Object
Implement enumerable.
-
#initialize(result, params = {}, &block) ⇒ Result
constructor
A new instance of Result.
- #metadata ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #paging ⇒ Object
Constructor Details
#initialize(result, params = {}, &block) ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 13 14 |
# File 'lib/fbgraph/result.rb', line 8 def initialize(result, params = {}, &block) result = result.respond_to?(:body) ? result.body : result.to_s @data = Hashie::Mash.new(JSON.parse(result)) rescue result @unparsed = result @params = params.symbolize_keys self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
37 38 39 |
# File 'lib/fbgraph/result.rb', line 37 def method_missing(method, *args, &block) data.send(method, *args, &block) rescue super(method, *args, &block) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/fbgraph/result.rb', line 6 def data @data end |
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/fbgraph/result.rb', line 6 def params @params end |
#unparsed ⇒ Object
Returns the value of attribute unparsed.
6 7 8 |
# File 'lib/fbgraph/result.rb', line 6 def unparsed @unparsed end |
Instance Method Details
#<=>(other) ⇒ Object
Implement Comparable
32 33 34 |
# File 'lib/fbgraph/result.rb', line 32 def <=>(other) (data <=> other.data) rescue 0 end |
#each(&block) ⇒ Object
Implement enumerable
25 26 27 28 |
# File 'lib/fbgraph/result.rb', line 25 def each(&block) return nil if data.blank? data.each(&block) end |
#metadata ⇒ Object
20 21 22 |
# File 'lib/fbgraph/result.rb', line 20 def data. end |
#paging ⇒ Object
16 17 18 |
# File 'lib/fbgraph/result.rb', line 16 def paging data.paging end |