Class: Cardio::Mod::Sow
Overview
The Sow class is for exporting data to mods’ data directories so that they can be used as seed data when the mod is installed.
https://docs.google.com/document/d/13K_ynFwfpHwc3t5gnLeAkZJZHco1wK063nJNYwU8qfc/edit#
Instance Method Summary collapse
-
#dump ⇒ Object
write yaml to file.
-
#field_tag_marks ⇒ Object
-
#filename ⇒ String
– MOD_DIR/data/ENVIRONMENT.yml.
-
#initialize(**args) ⇒ Sow
constructor
A new instance of Sow.
-
#new_data ⇒ Array <Hash>
-
#out ⇒ Object
if output mod given,.
Constructor Details
#initialize(**args) ⇒ Sow
Returns a new instance of Sow.
8 9 10 11 12 13 14 15 |
# File 'card/lib/cardio/mod/sow.rb', line 8 def initialize **args @mod = args[:mod] @name = args[:name] @cql = args[:cql] @podtype = args[:podtype] || (Rails.env.test? ? :test : :real) @items = args[:items] @field_tags = args[:field_tags] end |
Instance Method Details
#dump ⇒ Object
write yaml to file
45 46 47 48 49 |
# File 'card/lib/cardio/mod/sow.rb', line 45 def dump hash = output_hash File.write filename, hash.to_yaml puts "#{filename} now contains #{hash.size} items".green end |
#field_tag_marks ⇒ Object
22 23 24 25 26 |
# File 'card/lib/cardio/mod/sow.rb', line 22 def field_tag_marks @field_tag_marks ||= @field_tags.to_s.split(",").map do |mark| mark.strip.cardname.codename_or_string end end |
#filename ⇒ String
Returns – MOD_DIR/data/ENVIRONMENT.yml.
29 30 31 |
# File 'card/lib/cardio/mod/sow.rb', line 29 def filename @filename ||= File.join mod_path, "#{@podtype}.yml" end |
#new_data ⇒ Array <Hash>
18 19 20 |
# File 'card/lib/cardio/mod/sow.rb', line 18 def new_data @new_data ||= cards.map { |c| c.pod_hash field_tags: field_tag_marks } end |