Module: TxOcr

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

Defined Under Namespace

Classes: Base, CLI, Image, Text

Constant Summary collapse

VERSION =
'0.0.1'.freeze

Class Method Summary collapse

Class Method Details

.configObject

configをyamlから@cofigに取得



32
33
34
35
36
37
38
39
40
# File 'lib/tx_ocr/helper/config_helper.rb', line 32

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_ocr/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
# File 'lib/tx_ocr/helper/config_helper.rb', line 21

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

.save_configObject

現在の@configをyamlに保存



43
44
45
46
47
48
49
50
# File 'lib/tx_ocr/helper/config_helper.rb', line 43

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