Module: Cardio::Mod::Sow::CardSource

Included in:
Cardio::Mod::Sow
Defined in:
lib/cardio/mod/sow/card_source.rb

Overview

Fetch sow data form cards

Instance Method Summary collapse

Instance Method Details

#cardsObject



16
17
18
19
20
21
22
23
24
# File 'lib/cardio/mod/sow/card_source.rb', line 16

def cards
  if @name
    cards_from_name
  elsif @cql
    Card.search JSON.parse(@cql).reverse_merge(limit: 0)
  else
    raise Card::Error::NotFound, "must specify either name (-n) or CQL (-c)"
  end
end

#cards_from_nameObject



26
27
28
29
30
31
32
# File 'lib/cardio/mod/sow/card_source.rb', line 26

def cards_from_name
  case @items
  when :only then item_cards
  when true  then main_cards + item_cards
  else            main_cards
  end
end

#field_tag_marksObject



10
11
12
13
14
# File 'lib/cardio/mod/sow/card_source.rb', line 10

def field_tag_marks
  @field_tag_marks ||= @field_tags.to_s.split(",").map do |mark|
    mark.strip.cardname.codename_or_string
  end
end

#item_cardsObject



34
35
36
# File 'lib/cardio/mod/sow/card_source.rb', line 34

def item_cards
  main_cards.map(&:item_cards).flatten
end

#main_cardsObject



38
39
40
# File 'lib/cardio/mod/sow/card_source.rb', line 38

def main_cards
  @main_cards ||= @name.split(",").map { |n| require_card n }
end

#new_data_from_cardsObject



6
7
8
# File 'lib/cardio/mod/sow/card_source.rb', line 6

def new_data_from_cards
  cards.map { |c| c.pod_hash field_tags: field_tag_marks }
end

#require_card(name) ⇒ Object



42
43
44
# File 'lib/cardio/mod/sow/card_source.rb', line 42

def require_card name
  Card.fetch(name) || raise(Card::Error::NotFound, "card not found: #{name}")
end