Class: Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/baa_chan/layout.rb

Constant Summary collapse

LAYOUTS_PATH =
'lib/baa_chan/layouts'

Instance Method Summary collapse

Constructor Details

#initialize(broker) ⇒ Layout

Returns a new instance of Layout.



6
7
8
# File 'lib/baa_chan/layout.rb', line 6

def initialize(broker)
  @broker = broker
end

Instance Method Details

#attributesObject



10
11
12
13
14
# File 'lib/baa_chan/layout.rb', line 10

def attributes
  @attributes ||= YAML.safe_load(
    File.read(File.join(LAYOUTS_PATH, "#{@broker}.yml")), aliases: true
  )
end

#index(attr_name = caller_locations.first.label) ⇒ Object



20
21
22
# File 'lib/baa_chan/layout.rb', line 20

def index(attr_name = caller_locations.first.label)
  attributes[attr_name]['index'].to_i
end

#lineObject



16
17
18
# File 'lib/baa_chan/layout.rb', line 16

def line
  attributes[caller_locations.first.label]['line'].to_i
end

#regexp_for(attr) ⇒ Object



24
25
26
# File 'lib/baa_chan/layout.rb', line 24

def regexp_for(attr)
  attributes[attr]['regexp']
end

#tradeObject



28
29
30
# File 'lib/baa_chan/layout.rb', line 28

def trade
  @trade ||= attributes['trades']
end

#trade_index(asset) ⇒ Object



36
37
38
# File 'lib/baa_chan/layout.rb', line 36

def trade_index(asset)
  trade[asset][caller_locations.first.label]['index'].to_i
end

#trade_prefixObject



32
33
34
# File 'lib/baa_chan/layout.rb', line 32

def trade_prefix
  trade['prefix']
end

#trade_regexp(asset) ⇒ Object



40
41
42
# File 'lib/baa_chan/layout.rb', line 40

def trade_regexp(asset)
  trade[asset][caller_locations.first.label]['regexp']
end