Class: Uktt::Heading

Inherits:
Object
  • Object
show all
Defined in:
lib/uktt/heading.rb

Overview

A Chapter object for dealing with an API resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Heading

Returns a new instance of Heading.



6
7
8
9
10
11
# File 'lib/uktt/heading.rb', line 6

def initialize(opts = {})
  @heading_id = opts[:heading_id] || nil
  Uktt.configure(opts)
  @config = Uktt.config
  @response = nil
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/uktt/heading.rb', line 4

def config
  @config
end

#heading_idObject

Returns the value of attribute heading_id.



4
5
6
# File 'lib/uktt/heading.rb', line 4

def heading_id
  @heading_id
end

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/uktt/heading.rb', line 4

def response
  @response
end

Instance Method Details

#changesObject



29
30
31
32
33
# File 'lib/uktt/heading.rb', line 29

def changes
  return '@chapter_id cannot be nil' if @heading_id.nil?

  fetch "#{HEADING}/#{@heading_id}/changes.json"
end

#find(id) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/uktt/heading.rb', line 42

def find(id)
  return '@response is nil, run #retrieve first' unless @response
  
  response = @response.included.select do |obj|
    obj.id === id || obj.type === id
  end
  response.length == 1 ? response.first : response
end

#goods_nomenclaturesObject



19
20
21
22
23
# File 'lib/uktt/heading.rb', line 19

def goods_nomenclatures
  return '@chapter_id cannot be nil' if @heading_id.nil?

  fetch "#{GOODS_NOMENCLATURE}/heading/#{@heading_id}.json"
end

#noteObject



25
26
27
# File 'lib/uktt/heading.rb', line 25

def note
  'a heading cannot have a note'
end

#retrieveObject



13
14
15
16
17
# File 'lib/uktt/heading.rb', line 13

def retrieve
  return '@chapter_id cannot be nil' if @heading_id.nil?

  fetch "#{HEADING}/#{@heading_id}.json"
end