Class: Ruuuby::MetaData::IconvAPI

Inherits:
RuuubyAPIComponentCLI show all
Defined in:
lib/ruuuby/ruuuby/api/api_iconv.rb

Overview

Instance Attribute Summary

Attributes inherited from RuuubyAPIComponentCLI

#cmd_start

Attributes inherited from RuuubyEngineComponent

#versionable

Instance Method Summary collapse

Methods inherited from RuuubyAPIComponentCLI

#executed_cmd_returned_expected_output, #run_cmd, #run_cmd_raw

Methods inherited from RuuubyAPIComponent

#version

Methods inherited from RuuubyEngineComponent

#∅?

Constructor Details

#initialize(engine) ⇒ IconvAPI

Returns a new instance of IconvAPI.



13
14
15
16
# File 'lib/ruuuby/ruuuby/api/api_iconv.rb', line 13

def initialize(engine)
  super(engine, 'iconv')
  attribute_versionable('iconv (GNU libiconv 1.11)'){💎.engine.api_locale.api_iconv.version}
end

Instance Method Details

#_calculate_versionString

Returns:



45
# File 'lib/ruuuby/ruuuby/api/api_iconv.rb', line 45

def _calculate_version; self.run_cmd('--version')[0]; end

#healthy?Boolean

Returns:

  • (Boolean)


19
# File 'lib/ruuuby/ruuuby/api/api_iconv.rb', line 19

def healthy?; self.∃version? && self.∃_encoding?('UTF-8'); end

#supported_encodingsArray

Returns:



42
# File 'lib/ruuuby/ruuuby/api/api_iconv.rb', line 42

def supported_encodings; self.run_cmd('-l'); end

#∃_encoding?(encoding_to_find) ⇒ Boolean

Returns true, if the specified encoding was found locally.

Parameters:

Returns:

  • (Boolean)

    true, if the specified encoding was found locally

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ruuuby/ruuuby/api/api_iconv.rb', line 26

def ∃_encoding?(encoding_to_find)
  🛑str❓('encoding_to_find', encoding_to_find)
  begin
    results = self.run_cmd("-l | grep \"#{encoding_to_find}\"")
    if results.ary?
      results.{|e| return true if e.∋?(encoding_to_find)}
      return false
    else
      return results.∋?(encoding_to_find)
    end
  rescue ::TTY::Command::ExitError
    false
  end
end