Class: Overapp::TemplateFile::Params

Inherits:
Object
  • Object
show all
Includes:
Enumerable, FromHash
Defined in:
lib/overapp/template_file/params.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#full_bodyObject

Returns the value of attribute full_body.



5
6
7
# File 'lib/overapp/template_file/params.rb', line 5

def full_body
  @full_body
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/overapp/template_file/params.rb', line 5

def path
  @path
end

Instance Method Details

#bodyObject



6
# File 'lib/overapp/template_file/params.rb', line 6

def body; full_body; end

#each(&b) ⇒ Object



8
9
10
# File 'lib/overapp/template_file/params.rb', line 8

def each(&b)
  note_params.each(&b)
end

#has_note?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/overapp/template_file/params.rb', line 68

def has_note?
  note_params.any? { |x| x[:action].present? }
end

#note_params_single(one) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/overapp/template_file/params.rb', line 36

def note_params_single(one)
  res = {}
  note = one[:note]
  res[:body] = one[:body]

  if note
    lines = note.split("\n").select { |x| x.present? }
    if (lines.size == 1) && !(lines.first =~ /[a-z]+:/)
      res[:action] = lines.first.strip
    else
      lines.each do |line|
        parts = line.split(":").select { |x| x.present? }
        if parts.size > 2
          parts = [parts[0],parts[1..-1].join(":")]
        end
        parts = parts.map { |x| x.strip }
        raise "bad #{path} #{parts.inspect}" unless parts.size == 2
        res[parts[0].to_sym] = parts[1]
      end
    end
  end
  res
end

#split_note_and_bodyObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/overapp/template_file/params.rb', line 12

def split_note_and_body
  res = []
  remaining_body = full_body
  while remaining_body
    if remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)(<over(?:lay|app)>.+)/m
      note = $1
      rest = $2
      remaining_body = $3
      res << {:note => note, :body => rest}
    elsif remaining_body =~ /^<over(?:lay|app)>(.+)<\/over(?:lay|app)>(.*)/m
      note = $1
      rest = $2
      remaining_body = nil
      res << {:note => note, :body => rest}
    else
      res << {:note => nil, :body => remaining_body}
      remaining_body = nil
    end
  end
  res
rescue => exp
  raise "split_note_and_body #{path} #{exp.message}"
end