Class: Ektoplayer::ColumnFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/ektoplayer/config.rb

Class Method Summary collapse

Class Method Details

._parse_markup(format) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/ektoplayer/config.rb', line 39

def self._parse_markup(format)
   Nokogiri::XML("<f>#{format}</f>").first_element_child.
      children.map do |fmt|
         fmt1 = fmt.attributes.map do |name,a|
            [name.to_sym, a.value]
         end.to_h.update(tag: fmt.name)
         fmt1[:text] = fmt.text if fmt1[:tag] == 'text'
         fmt1
   end
end

.parse_column_format(format) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ektoplayer/config.rb', line 6

def self.parse_column_format(format)
   self.parse_simple_format(format).
      select { |f| f[:tag] != 'text' }.
      map do |fmt|
      fmt[:size]    = fmt[:size].to_i      if fmt[:size]
      fmt[:rel]     = fmt[:rel].to_i       if fmt[:rel]
      fmt[:justify] = fmt[:justify].to_sym if fmt[:justify]

      begin
         fail 'Missing size= or rel=' if (!fmt[:size] and !fmt[:rel])
         fail 'size= and rel= are mutually exclusive' if (fmt[:size] and fmt[:rel])
      rescue 
         fail "column: #{fmt[:tag]}: #{$!}"
      end

      fmt
   end
end

.parse_simple_format(format) ⇒ Object



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

def self.parse_simple_format(format)
   self._parse_markup(format).map do |fmt|
      fmt[:curses_attrs] = [
         (fmt[:fg] and Integer(fmt[:fg]) rescue fmt[:fg].to_sym),
         (fmt[:bg] and Integer(fmt[:bg]) rescue fmt[:bg].to_sym),
      ]
      fmt[:curses_attrs] << :bold      if fmt[:bold]
      fmt[:curses_attrs] << :blink     if fmt[:blink]
      fmt[:curses_attrs] << :standout  if fmt[:standout]
      fmt[:curses_attrs] << :underline if fmt[:underline]
      fmt
   end
end