Class: Analects::Library

Inherits:
Object
  • Object
show all
Defined in:
lib/analects/library.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Library

Returns a new instance of Library.



11
12
13
# File 'lib/analects/library.rb', line 11

def initialize(options = {})
  @options = options.freeze
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/analects/library.rb', line 9

def options
  @options
end

Instance Method Details

#cedictObject



36
37
38
39
40
41
42
# File 'lib/analects/library.rb', line 36

def cedict
  @cedict ||= create_source(
    :cedict,
    data_file: 'cedict_1_0_ts_utf-8_mdbg.txt',
    retrieval: [ :http, :gunzip, :save ]
  )
end

#chise_idsObject



44
45
46
47
48
49
# File 'lib/analects/library.rb', line 44

def chise_ids
  @chise_ids ||= create_source(
    :chise_ids,
    retrieval: :git
  )
end

#data_dirObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/analects/library.rb', line 15

def data_dir
  if options[:data_dir]
    Dir.mkdir(options[:data_dir]) unless File.exist?(options[:data_dir])
    return options[:data_dir]
  end
  File.join(Dir.home, '.analects').tap do |dir|
    unless File.exist? dir
      Dir.mkdir dir
    end
  end
end

#hskObject



58
59
60
61
62
63
64
# File 'lib/analects/library.rb', line 58

def hsk
  @hsk ||= create_source(
    :hsk,
    data_file: 'hsk.csv',
    retrieval: [ :http, :save ]
  )
end

#sourcesObject



27
28
29
30
31
32
33
34
# File 'lib/analects/library.rb', line 27

def sources
  [
    cedict,
    chise_ids,
    unihan,
    hsk
  ]
end

#unihanObject



51
52
53
54
55
56
# File 'lib/analects/library.rb', line 51

def unihan
  @unihan ||= create_source(
    :unihan,
    retrieval: [ :http, :unzip ]
  )
end