Class: Codex::Content::Descriptor

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

Overview

Wrap the parameters to :code

:code file.rb[:part class=xxx]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Descriptor

Returns a new instance of Descriptor.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/codex/content.rb', line 13

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

  if 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.



10
11
12
# File 'lib/codex/content.rb', line 10

def css_class
  @css_class
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



9
10
11
# File 'lib/codex/content.rb', line 9

def file_name
  @file_name
end

#langObject (readonly)

Returns the value of attribute lang.



11
12
13
# File 'lib/codex/content.rb', line 11

def lang
  @lang
end

#partObject (readonly)

Returns the value of attribute part.



9
10
11
# File 'lib/codex/content.rb', line 9

def part
  @part
end

Instance Method Details

#parse_params(params) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/codex/content.rb', line 25

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