Class: Translator::ConfigFile
- Inherits:
-
Object
- Object
- Translator::ConfigFile
- Defined in:
- lib/translator/config_file.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Class Method Summary collapse
Instance Method Summary collapse
- #config_file_path ⇒ Object
-
#initialize(from, to) ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #save_config ⇒ Object
Constructor Details
#initialize(from, to) ⇒ ConfigFile
Returns a new instance of ConfigFile.
5 6 7 8 9 10 11 |
# File 'lib/translator/config_file.rb', line 5 def initialize(from, to) from = 'auto' if from.empty? raise ArgumentError, 'Precisa passar qual idioma deseja traduzir' if to.empty? @from = from.downcase @to = to.downcase end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/translator/config_file.rb', line 3 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
3 4 5 |
# File 'lib/translator/config_file.rb', line 3 def to @to end |
Class Method Details
.default_from ⇒ Object
38 39 40 |
# File 'lib/translator/config_file.rb', line 38 def default_from get_default_config[:from] end |
.default_to ⇒ Object
34 35 36 |
# File 'lib/translator/config_file.rb', line 34 def default_to get_default_config[:to] end |
.exist? ⇒ Boolean
42 43 44 |
# File 'lib/translator/config_file.rb', line 42 def exist? File.exist?("#{Dir.home}/.translator") end |
.get_default_config ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/translator/config_file.rb', line 25 def get_default_config config = [] File.open("#{Dir.home}/.translator").each_line do |l| config << l.delete("\n") end { from: config[0], to: config[1] } end |
Instance Method Details
#config_file_path ⇒ Object
13 14 15 |
# File 'lib/translator/config_file.rb', line 13 def config_file_path "#{Dir.home}/.translator" end |
#save_config ⇒ Object
17 18 19 20 21 22 |
# File 'lib/translator/config_file.rb', line 17 def save_config File.open(config_file_path, 'w') do |f| f.write("#{from}\n#{to}\n") f.close end end |