Class: Characteristics

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

Constant Summary collapse

VERSION =
"0.2.0".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char) ⇒ Characteristics

Returns a new instance of Characteristics.



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

def initialize(char)
  @is_valid = char.valid_encoding?
  @encoding = char.encoding
  @encoding_name = @encoding.name
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



41
42
43
# File 'lib/characteristics.rb', line 41

def encoding
  @encoding
end

Class Method Details

.create(char) ⇒ Object



37
38
39
# File 'lib/characteristics.rb', line 37

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

.create_for_type(char, type) ⇒ Object



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

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



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

def self.type_from_encoding_name(encoding_name)
  case encoding_name
  when "US-ASCII"
    :ascii
  when "ASCII-8BIT"
    :binary
  when /^UTF-/
    :unicode
  when /^ISO-8859-/, /^Windows-125/
    :byte
  else
    raise ArgumentError, "encoding <#{encoding_name}> not supported"
  end
end

Instance Method Details

#assigned?Boolean

Returns:

  • (Boolean)


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

def assigned?
end

#blank?Boolean

Returns:

  • (Boolean)


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

def blank?
end

#control?Boolean

Returns:

  • (Boolean)


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

def control?
end

#unicode?Boolean

Returns:

  • (Boolean)


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

def unicode?
  false
end

#valid?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/characteristics.rb', line 49

def valid?
  @is_valid
end