Class: Characteristics

Inherits:
Object
  • Object
show all
Defined in:
lib/characteristics.rb,
lib/characteristics/version.rb

Constant Summary collapse

VERSION =
"1.7.1"
UNICODE_VERSION =
"16.0.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char) ⇒ Characteristics

Returns a new instance of Characteristics.

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
# File 'lib/characteristics.rb', line 45

def initialize(char)
  raise ArgumentError, "Do not use abstract Characteristics.new(char) directly, please use Characteristics.create(char)" if self.class == Characteristics

  @is_valid = char.valid_encoding?
  @encoding = char.encoding
  @encoding_name = @encoding.name
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



43
44
45
# File 'lib/characteristics.rb', line 43

def encoding
  @encoding
end

Class Method Details

.create(char) ⇒ Object



39
40
41
# File 'lib/characteristics.rb', line 39

def self.create(char)
  create_for_type(char, type_from_encoding_name(char.encoding.name))
end

.create_for_type(char, type) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/characteristics.rb', line 26

def self.create_for_type(char, type)
  case type
  when :unicode
    UnicodeCharacteristics.new(char)
  when :byte
    ByteCharacteristics.new(char)
  when :ascii
    AsciiCharacteristics.new(char)
  else
    BinaryCharacteristics.new(char)
  end
end

.type_from_encoding_name(encoding_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/characteristics.rb', line 11

def self.type_from_encoding_name(encoding_name)
  case encoding_name
  when "US-ASCII", "GB1988"
    :ascii
  when "ASCII-8BIT"
    :binary
  when /^UTF-?/
    :unicode
  when /^ISO-8859-/, /^Windows-125/, /^(IBM|CP85)/, /^mac/, 'TIS-620', 'Windows-874', /^KOI8-/
    :byte
  else
    raise ArgumentError, "encoding <#{encoding_name}> not supported"
  end
end

Instance Method Details

#assigned?Boolean

Returns:

  • (Boolean)


60
61
# File 'lib/characteristics.rb', line 60

def assigned?
end

#bidi_control?Boolean

Returns:

  • (Boolean)


81
82
# File 'lib/characteristics.rb', line 81

def bidi_control?
end

#blank?Boolean

Returns:

  • (Boolean)


75
76
# File 'lib/characteristics.rb', line 75

def blank?
end

#c0?Boolean

Returns:

  • (Boolean)


66
67
# File 'lib/characteristics.rb', line 66

def c0?
end

#c1?Boolean

Returns:

  • (Boolean)


72
73
# File 'lib/characteristics.rb', line 72

def c1?
end

#control?Boolean

Returns:

  • (Boolean)


63
64
# File 'lib/characteristics.rb', line 63

def control?
end

#delete?Boolean

Returns:

  • (Boolean)


69
70
# File 'lib/characteristics.rb', line 69

def delete?
end

#docomo?Boolean

private use emojis

Returns:

  • (Boolean)


93
94
# File 'lib/characteristics.rb', line 93

def docomo?
end

#format?Boolean

Returns:

  • (Boolean)


78
79
# File 'lib/characteristics.rb', line 78

def format?
end

#kddi?Boolean

private use emojis

Returns:

  • (Boolean)


85
86
# File 'lib/characteristics.rb', line 85

def kddi?
end

#softbank?Boolean

private use emojis

Returns:

  • (Boolean)


89
90
# File 'lib/characteristics.rb', line 89

def softbank?
end

#unicode?Boolean

Returns:

  • (Boolean)


57
58
# File 'lib/characteristics.rb', line 57

def unicode?
end

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/characteristics.rb', line 53

def valid?
  @is_valid
end