Module: CodePages

Defined in:
lib/code_pages.rb,
lib/code-pages/version.rb,
lib/code-pages/importer.rb,
lib/code-pages/code_page.rb

Defined Under Namespace

Classes: CodePage, Importer

Constant Summary collapse

VERSION =
'1.2.0'

Class Method Summary collapse

Class Method Details

.[](name_or_id) ⇒ Object



8
9
10
# File 'lib/code_pages.rb', line 8

def [](name_or_id)
  from_name(name_or_id) || from_id(name_or_id)
end

.allObject



24
25
26
27
28
29
30
31
32
# File 'lib/code_pages.rb', line 24

def all
  @all ||= manifest.each_with_object({}) do |props, ret|
    ret[props['name']] = CodePage.new(
      props['code_page'],
      props['name'],
      File.join(resources_dir, "#{props['name']}.yml")
    )
  end
end

.manifestObject



34
35
36
37
38
# File 'lib/code_pages.rb', line 34

def manifest
  @manifest ||= YAML.load_file(
    File.join(resources_dir, 'code_page_manifest.yml')
  )
end

.resources_dirObject



40
41
42
# File 'lib/code_pages.rb', line 40

def resources_dir
  @resources_dir ||= File.expand_path('../../resources', __FILE__)
end

.supported_idsObject



12
13
14
# File 'lib/code_pages.rb', line 12

def supported_ids
  @supported_ids ||= all.map { |_, cp| cp.id }.compact
end

.supported_namesObject



16
17
18
# File 'lib/code_pages.rb', line 16

def supported_names
  @supported_names ||= all.keys
end

.supports?(id_or_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/code_pages.rb', line 20

def supports?(id_or_name)
  supported_ids.include?(id_or_name) || supported_names.include?(id_or_name)
end