Class: Dongjia::RouterItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defining_line) ⇒ RouterItem

Returns a new instance of RouterItem.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dongjia_router.rb', line 30

def initialize(defining_line)
  @defining_line = defining_line.strip
  @body = ''
  @prefix = nil
  prefix_len = 0
  if @defining_line.start_with?('@RedirectObj(') || @defining_line.start_with?('@redirectObj(')
    @prefix = 'RedirectObj'
    prefix_len = @prefix.length + 2
  elsif @defining_line.start_with?('@Redirect(') || @defining_line.start_with?('@redirect(')
    @prefix = 'Redirect'
    prefix_len = @prefix.length + 2
  end
  
  if @prefix != nil
    end_index = @defining_line.index(',') || @defining_line.index(')')
    if !end_index.nil?
      @redirect_type = @defining_line[prefix_len, end_index - prefix_len]
    end
  end
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



26
27
28
# File 'lib/dongjia_router.rb', line 26

def body
  @body
end

#pre_lineObject

Returns the value of attribute pre_line.



28
29
30
# File 'lib/dongjia_router.rb', line 28

def pre_line
  @pre_line
end

#redirect_typeObject

Returns the value of attribute redirect_type.



27
28
29
# File 'lib/dongjia_router.rb', line 27

def redirect_type
  @redirect_type
end

Instance Method Details

#outputObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dongjia_router.rb', line 51

def output
  del_count = @defining_line.end_with?('{') ? 1 : 0
  result = "#pregma mark - "
  result << @defining_line[0, @defining_line.length - del_count].strip

  if @pre_line && @pre_line.start_with?('/')
    result << " " << @pre_line.gsub(/^\/+/, '').strip
  end

  result << "\n"
  result << "_" << @prefix << @redirect_type << "\n"
  result << (del_count == 1 ? "{\n" : "")
  result << @body << "\n\n"
  result
end