Class: EBPS::Text::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/ebps/text/format.rb

Constant Summary collapse

VALID_FORMATS =
%w{b i pre sub sup u}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Format

Returns a new instance of Format.



6
7
8
9
10
11
# File 'lib/ebps/text/format.rb', line 6

def initialize(*args)
  @values = []
  augment *args
  @start = 0
  @end = -1
end

Instance Attribute Details

#endObject

Returns the value of attribute end.



4
5
6
# File 'lib/ebps/text/format.rb', line 4

def end
  @end
end

#startObject

Returns the value of attribute start.



4
5
6
# File 'lib/ebps/text/format.rb', line 4

def start
  @start
end

#valuesObject

Returns the value of attribute values.



4
5
6
# File 'lib/ebps/text/format.rb', line 4

def values
  @values
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/ebps/text/format.rb', line 21

def ==(other)
  case other
  when Format
    @values == other.values
  when Array
    @values == (other & VALID_FORMATS).sort
  else
    false
  end
end

#augment(*args) ⇒ Object



12
13
14
15
16
17
# File 'lib/ebps/text/format.rb', line 12

def augment(*args)
  @values.concat(args & VALID_FORMATS)
  @values.sort!
  @values.uniq!
  @values
end

#rangeObject



18
19
20
# File 'lib/ebps/text/format.rb', line 18

def range
  @start..@end
end