Class: Cliptic::Config::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/cliptic/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReader

Returns a new instance of Reader.



60
61
62
# File 'lib/cliptic/config.rb', line 60

def initialize
  @lines = File.read(File_Path).each_line.map.to_a
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



59
60
61
# File 'lib/cliptic/config.rb', line 59

def lines
  @lines
end

Instance Method Details

#read(key:) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/cliptic/config.rb', line 63

def read(key:)
  lines.grep(/^\s*#{key}/)
    .map{|l| l.gsub(/^\s*#{key}\s+/, "")
    .split(/\s+/)}
    .map{|k, v| [k.to_sym, v.to_i]}
    .to_h
end