Class: CardPrinter::Parser::TrelloJsonExport

Inherits:
Base
  • Object
show all
Defined in:
lib/card_printer/parser/trello_json_export.rb

Defined Under Namespace

Classes: Card, List

Instance Attribute Summary

Attributes inherited from Base

#iostream

Instance Method Summary collapse

Methods inherited from Base

#initialize, #parse_line

Constructor Details

This class inherits a constructor from CardPrinter::Parser::Base

Instance Method Details

#cards_for_list_id(list_id) ⇒ Object



29
30
31
32
33
34
# File 'lib/card_printer/parser/trello_json_export.rb', line 29

def cards_for_list_id(list_id)
  data['cards']
    .select { |card| card['idList'] == list_id }
    .reject { |card| if card['closed'] then puts "card #{card['name']} closed"; end; card['closed'] == true }
    .map { |card| Card.new(card) }
end

#dataObject



17
18
19
# File 'lib/card_printer/parser/trello_json_export.rb', line 17

def data
  @data ||= JSON.load(iostream)
end

#label_of(card) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/card_printer/parser/trello_json_export.rb', line 62

def label_of(card)
  if card.labels.any?
    card.labels.first['name']
  else
    ""
  end
end

#listsObject



21
22
23
24
25
26
27
# File 'lib/card_printer/parser/trello_json_export.rb', line 21

def lists
  data['lists'].map do |list|
    List.new(list).tap do |l|
      l.cards = cards_for_list_id(l.id)
    end
  end
end

#parseObject



9
10
11
12
13
14
15
# File 'lib/card_printer/parser/trello_json_export.rb', line 9

def parse
  lists.map do |list|
    list.cards.map do |card|
      story_from_card(list, card)
    end
  end.flatten
end

#story_from_card(list, card) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/card_printer/parser/trello_json_export.rb', line 36

def story_from_card(list, card)
  CardPrinter::Story.new(
    name: "#{card.name}",
    description: card.desc,
    story_type: story_type(card),
    estimate: "",
    label: "",
    id: "##{card.idShort}"
  )
end

#story_type(card) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/card_printer/parser/trello_json_export.rb', line 47

def story_type(card)
  case label_of(card)
  when /feature/i
    "feature"
  when /bug/i
    "bug"
  when /chore/i
    "chore"
  when /retro/i
    "retro"
  else
    "other"
  end
end