Class: Cardio::Mod::Poop

Inherits:
Object
  • Object
show all
Defined in:
lib/cardio/mod/poop.rb

Overview

POOP (or Plain Old OutPut) is our nickname for our standard card YAML, used to define cards associated with mods.

Monkeys throw it around, and Sharks can eat it (if you believe this guy: www.youtube.com/watch?v=VvEa4NSqw7I).

docs.google.com/document/d/13K_ynFwfpHwc3t5gnLeAkZJZHco1wK063nJNYwU8qfc/edit#

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Poop

Returns a new instance of Poop.



11
12
13
14
15
16
17
18
# File 'lib/cardio/mod/poop.rb', line 11

def initialize **args
  @mod = args[:mod]
  @name = args[:name]
  @cql = args[:cql]
  @env = args[:env] || Rails.env
  @items = args[:items]
  @field_tags = args[:field_tags]
end

Instance Method Details

#dumpObject

write yaml to file



48
49
50
51
52
# File 'lib/cardio/mod/poop.rb', line 48

def dump
  hash = output_hash
  File.write filename, hash.to_yaml
  puts "#{filename} now contains #{hash.size} items".green
end

#field_tag_marksObject



25
26
27
28
29
# File 'lib/cardio/mod/poop.rb', line 25

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

#filenameString

Returns – MOD_DIR/data/ENVIRONMENT.yml.

Returns:

  • (String)

    – MOD_DIR/data/ENVIRONMENT.yml



32
33
34
# File 'lib/cardio/mod/poop.rb', line 32

def filename
  @filename ||= File.join mod_path, "#{@env}.yml"
end

#new_dataArray <Hash>

Returns:

  • (Array <Hash>)


21
22
23
# File 'lib/cardio/mod/poop.rb', line 21

def new_data
  @new_data ||= cards.map { |c| c.export_hash field_tags: field_tag_marks }
end

#outObject

if output mod given,



37
38
39
40
41
42
43
44
45
# File 'lib/cardio/mod/poop.rb', line 37

def out
  Card::Cache.reset_all
  @mod ? dump : puts(new_data.to_yaml.yellow)
  :success
rescue Card::Error::NotFound => e
  e.message
rescue JSON::ParserError => e
  e.message
end