Class: Nele::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/nele-cli/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Config

Returns a new instance of Config.



5
6
7
8
# File 'lib/nele-cli/config.rb', line 5

def initialize path
  @path = path
  @params = load_file
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/nele-cli/config.rb', line 3

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/nele-cli/config.rb', line 3

def path
  @path
end

Class Method Details

.create(path) ⇒ Object



19
20
21
# File 'lib/nele-cli/config.rb', line 19

def create path
  File.open(path, 'w') { |f| YAML.dump file_template, f }
end

.file_templateObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nele-cli/config.rb', line 23

def file_template
  { :default => "ms",
    :translators => {
      :ms => {
        :appId => "YOUR_KEY",
        :from => "en",
        :to => "pl",
        :url => "http://api.microsofttranslator.com/v2/" \
        "Http.svc/Translate"
      },
      :babelfish => {
        :url => "http://babelfish.yahoo.com/translate_txt",
        :lp => "en_es"
      }
    }
  }
end

Instance Method Details

#default_translatorObject



14
15
16
# File 'lib/nele-cli/config.rb', line 14

def default_translator
  @default_translator ||= params[:default]
end

#load_fileObject



42
43
44
45
46
47
48
# File 'lib/nele-cli/config.rb', line 42

def load_file
  begin
    @params ||= YAML.load_file path
  rescue Errno::ENOENT
    print "Can't find #{path}\n"
  end
end

#translatorsObject



10
11
12
# File 'lib/nele-cli/config.rb', line 10

def translators
  @translators ||= params[:translators]
end