Class: Chemtrail::ReferencePresenter
- Inherits:
-
Object
- Object
- Chemtrail::ReferencePresenter
- Defined in:
- lib/chemtrail/reference_presenter.rb
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
Instance Method Summary collapse
- #hashlike? ⇒ Boolean
-
#initialize(argument) ⇒ ReferencePresenter
constructor
A new instance of ReferencePresenter.
- #iterable? ⇒ Boolean
- #reference? ⇒ Boolean
- #to_parameter ⇒ Object
Constructor Details
#initialize(argument) ⇒ ReferencePresenter
Returns a new instance of ReferencePresenter.
4 5 6 |
# File 'lib/chemtrail/reference_presenter.rb', line 4 def initialize(argument) @argument = argument end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
2 3 4 |
# File 'lib/chemtrail/reference_presenter.rb', line 2 def argument @argument end |
Instance Method Details
#hashlike? ⇒ Boolean
16 17 18 |
# File 'lib/chemtrail/reference_presenter.rb', line 16 def hashlike? argument.respond_to?(:to_hash) end |
#iterable? ⇒ Boolean
12 13 14 |
# File 'lib/chemtrail/reference_presenter.rb', line 12 def iterable? argument.respond_to?(:each) end |
#reference? ⇒ Boolean
8 9 10 |
# File 'lib/chemtrail/reference_presenter.rb', line 8 def reference? argument.respond_to?(:to_reference) end |
#to_parameter ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chemtrail/reference_presenter.rb', line 20 def to_parameter if reference? argument.to_reference else if iterable? if hashlike? argument.reduce(argument) { |h, (k, v)| h[k] = self.class.new(v).to_parameter; h } else argument.map { |item| self.class.new(item).to_parameter } end else argument end end end |