Class: Menthol::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/menthol/profile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(providers) ⇒ Profile

Returns a new instance of Profile.



6
7
8
# File 'lib/menthol/profile.rb', line 6

def initialize(providers)
  @providers = providers
end

Instance Attribute Details

#providersObject (readonly)

Returns the value of attribute providers.



10
11
12
# File 'lib/menthol/profile.rb', line 10

def providers
  @providers
end

Class Method Details

.configure(config_file_path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/menthol/profile.rb', line 12

def self.configure(config_file_path)
  configuration = YAML.load(File.read(config_file_path))

  providers = configuration.map do |c|
    Menthol.const_get(c["provider"]).new(
      c["name"],
      c["username"],
      c["password"],
      c["accounts"]
    )
  end

  new(providers)
end

Instance Method Details

#amountObject



31
32
33
# File 'lib/menthol/profile.rb', line 31

def amount
  @providers.map(&:amount).reduce(Money.new(0, "THB"), &:+)
end

#sync_all!Object



27
28
29
# File 'lib/menthol/profile.rb', line 27

def sync_all!
  @providers.each(&:sync!)
end