Class: Codex::CodeFilter::Descriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/codex/filters/code_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Descriptor

Returns a new instance of Descriptor.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/codex/filters/code_filter.rb', line 7

def initialize(string)
  @css_class = "code-normal"
  @lang = "ruby"

  if string && string =~ /^\[(.*)\]/
    @file_name = nil
    parse_params($1.dup)
  elsif string && string =~ /(.*?)\[(.*)\]/
    @file_name = $1
    parse_params($2.dup)
  else
    @file_name = string
  end
end

Instance Attribute Details

#css_classObject (readonly)

Returns the value of attribute css_class.



4
5
6
# File 'lib/codex/filters/code_filter.rb', line 4

def css_class
  @css_class
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



3
4
5
# File 'lib/codex/filters/code_filter.rb', line 3

def file_name
  @file_name
end

#langObject (readonly)

Returns the value of attribute lang.



5
6
7
# File 'lib/codex/filters/code_filter.rb', line 5

def lang
  @lang
end

#partObject (readonly)

Returns the value of attribute part.



3
4
5
# File 'lib/codex/filters/code_filter.rb', line 3

def part
  @part
end

Instance Method Details

#parse_params(params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/codex/filters/code_filter.rb', line 22

def parse_params(params)
  params.split.each do |param|
    if param =~ /(.*?)=(.*)/
      case $1
      when "class"
        @css_class = $2
      when "lang"
        @lang = $2
      else
        fail "Unknown parameter #{$1} in '#{params}'"
      end
    else
      @part = param
    end
  end
end