Module: TxNlp

Defined in:
lib/tx_nlp.rb,
lib/tx_nlp/cli.rb,
lib/tx_nlp/base.rb,
lib/tx_nlp/text.rb,
lib/tx_nlp/version.rb,
lib/tx_nlp/helper/config_helper.rb

Defined Under Namespace

Classes: Base, CLI, Text

Constant Summary collapse

VERSION =
'0.0.3'.freeze

Class Method Summary collapse

Class Method Details

.configObject

configをyamlから@cofigに取得



34
35
36
37
38
39
40
41
42
# File 'lib/tx_nlp/helper/config_helper.rb', line 34

def self.config
  yml_path = get_config_path + '/settings.yml'
  yml_file = YAML.load_file(yml_path)
  if yml_file
    @config = yml_file
  else
    File.open(yml_path, 'w') { |f| YAML.dump(@config, f) }
  end
end

.configure(opts = {}) ⇒ Object

Configure through hash



13
14
15
16
17
18
19
# File 'lib/tx_nlp/helper/config_helper.rb', line 13

def self.configure(opts = {})
  config
  opts.each do |k, v|
    @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym
  end
  save_config
end

.get_config_pathObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tx_nlp/helper/config_helper.rb', line 21

def self.get_config_path
  config_path = Dir.home + '/.tx_nlp'
  if Dir.exist?(config_path)
    # use user settings
    config_path
  else
    #system "mkdir #{config_path}"
    config_path
    #raise "Can't find config directory. please init by command: 'mygem config'.'"
  end
end

.save_configObject

現在の@configをyamlに保存



45
46
47
48
49
50
51
52
# File 'lib/tx_nlp/helper/config_helper.rb', line 45

def self.save_config
  yml_path = get_config_path + '/settings.yml'
  if File.exist?(yml_path)
    File.open(yml_path, 'w') { |f| YAML.dump(@config, f) }
  else
    raise "Can't find #{yml_path}. please set configure."
  end
end