Class: Nele::Config
- Inherits:
-
Object
- Object
- Nele::Config
- Defined in:
- lib/nele-cli/config.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #default_translator ⇒ Object
-
#initialize(path) ⇒ Config
constructor
A new instance of Config.
- #load_file ⇒ Object
- #translators ⇒ Object
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
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/nele-cli/config.rb', line 3 def params @params end |
#path ⇒ Object (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_template ⇒ Object
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_translator ⇒ Object
14 15 16 |
# File 'lib/nele-cli/config.rb', line 14 def default_translator @default_translator ||= params[:default] end |
#load_file ⇒ Object
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 |
#translators ⇒ Object
10 11 12 |
# File 'lib/nele-cli/config.rb', line 10 def translators @translators ||= params[:translators] end |