Class: Alula::Meta

Inherits:
Object show all
Defined in:
lib/alula/meta.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(meta) ⇒ Meta

Returns a new instance of Meta.



5
6
7
8
9
10
11
12
# File 'lib/alula/meta.rb', line 5

def initialize(meta)
  meta_hash = coerce_to_hash(meta)

  page_data = extract_page(meta_hash)
  build_pagination(page_data)

  @custom_attributes = build_custom_attributes(meta_hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



22
23
24
25
26
# File 'lib/alula/meta.rb', line 22

def method_missing(method_name, *args, &block)
  return custom_attributes[method_name] if custom_attributes.key?(method_name)

  super
end

Instance Attribute Details

#custom_attributesObject (readonly)

Returns the value of attribute custom_attributes.



3
4
5
# File 'lib/alula/meta.rb', line 3

def custom_attributes
  @custom_attributes
end

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/alula/meta.rb', line 3

def number
  @number
end

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/alula/meta.rb', line 3

def page
  @page
end

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/alula/meta.rb', line 3

def size
  @size
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/alula/meta.rb', line 3

def total
  @total
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/alula/meta.rb', line 14

def [](key)
  custom_attributes[normalize_key(key)]
end

#fetch(key, *args, &block) ⇒ Object



18
19
20
# File 'lib/alula/meta.rb', line 18

def fetch(key, *args, &block)
  custom_attributes.fetch(normalize_key(key), *args, &block)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/alula/meta.rb', line 28

def respond_to_missing?(method_name, include_private = false)
  custom_attributes.key?(method_name) || super
end