Class: Bumbleworks::Api::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/bumbleworks/api/lib/presenter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presented, in_collection: false) ⇒ Presenter

Returns a new instance of Presenter.



22
23
24
25
# File 'lib/bumbleworks/api/lib/presenter.rb', line 22

def initialize(presented, in_collection: false)
  @presented = presented
  @in_collection = in_collection
end

Instance Attribute Details

#presentedObject (readonly)

Returns the value of attribute presented.



4
5
6
# File 'lib/bumbleworks/api/lib/presenter.rb', line 4

def presented
  @presented
end

Class Method Details

.from_array(array) ⇒ Object



15
16
17
18
19
# File 'lib/bumbleworks/api/lib/presenter.rb', line 15

def from_array(array)
  array.map { |presented|
    new(presented, in_collection: true)
  }
end

.present(presented) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/bumbleworks/api/lib/presenter.rb', line 7

def present(presented)
  if presented.is_a?(Array)
    from_array(presented)
  else
    new(presented)
  end
end

Instance Method Details

#in_collection?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/bumbleworks/api/lib/presenter.rb', line 27

def in_collection?
  @in_collection == true
end