Class: Store

Inherits:
Object
  • Object
show all
Defined in:
app/models/store.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type, name, tag) ⇒ Store

Returns a new instance of Store.



5
6
7
8
9
10
# File 'app/models/store.rb', line 5

def initialize(id, type, name, tag)
  @id = id
  @type = type
  @name = name
  @tag = tag
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'app/models/store.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/models/store.rb', line 3

def name
  @name
end

#tagObject

Returns the value of attribute tag.



3
4
5
# File 'app/models/store.rb', line 3

def tag
  @tag
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'app/models/store.rb', line 3

def type
  @type
end

Class Method Details

.all(session_id:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'app/models/store.rb', line 12

def self.all(session_id:)
  @all ||= begin
    stores_request = Mediaflux::StoreListRequest.new(session_token: session_id)
    data = stores_request.stores
    stores = data.map do |mf_store|
      Store.new(mf_store[:id], mf_store[:type], mf_store[:name], mf_store[:tag])
    end
    stores
  end
end

.default(session_id:) ⇒ Object



27
28
29
# File 'app/models/store.rb', line 27

def self.default(session_id:)
  all(session_id: session_id).first
end

.get_by_name(name, session_id:) ⇒ Object



23
24
25
# File 'app/models/store.rb', line 23

def self.get_by_name(name, session_id:)
  all(session_id: session_id).find { |store| store.name == name }
end