Class: Features2Cards::Card

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, body, footer = nil) ⇒ Card

Returns a new instance of Card.



46
47
48
49
50
# File 'lib/features2cards/card.rb', line 46

def initialize(type, body, footer = nil)
  @type = type
  @body = body
  @footer = footer
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/features2cards/card.rb', line 5

def body
  @body
end

Returns the value of attribute footer.



6
7
8
# File 'lib/features2cards/card.rb', line 6

def footer
  @footer
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/features2cards/card.rb', line 4

def type
  @type
end

Class Method Details

.for_feature(feature) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/features2cards/card.rb', line 8

def self.for_feature(feature)
  actual_feature = feature.to_sexp()
  actual_feature.shift
  actual_feature.shift
  title = actual_feature[0].split("\n").first
  footer = title
  body  = actual_feature[0].gsub(/^\s*#{title}\n/, '')
  card = [new(title, body, "")]
  footer = title

  actual_feature.shift
  scenarios = actual_feature

  scenarios.map do |scenario|
    case(scenario[0])
      when :scenario_outline
        scenario.shift
      when :scenario
        scenario.shift
        scenario.shift
      when :tag
        next
      when :comment
        next
    end
     title = scenario[0] + " " + scenario[1]
     scenario.shift
     scenario.shift
     body = ""
     scenario.map do |step|
       body += step[2] + " " + step[3] + "\n" if step[0] == :step or step[0] == :step_invocation
     end
     card.push(new(title, body, footer))
  end

  return card
end