Class: Card::SetPattern
Class Attribute Summary collapse
-
.anchorless ⇒ Object
Returns the value of attribute anchorless.
-
.assigns_type ⇒ Object
Returns the value of attribute assigns_type.
-
.junction_only ⇒ Object
Returns the value of attribute junction_only.
-
.pattern_code ⇒ Object
Returns the value of attribute pattern_code.
-
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
Class Method Summary collapse
- .anchorless? ⇒ Boolean
- .find(pattern_code) ⇒ Object
- .junction_only? ⇒ Boolean
- .new(card) ⇒ Object
- .pattern ⇒ Object
- .pattern_applies?(card) ⇒ Boolean
- .register(pattern_code, opts = {}) ⇒ Object
- .write_tmp_file(pattern_code, from_file, seq) ⇒ Object
Instance Method Summary collapse
- #anchor_codenames ⇒ Object
- #format_module_list(klass) ⇒ Object
-
#initialize(card) ⇒ SetPattern
constructor
Instance methods.
- #inspect ⇒ Object
- #module_key ⇒ Object
- #module_list ⇒ Object
- #pattern ⇒ Object
- #rule_set_key ⇒ Object
- #safe_key ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(card) ⇒ SetPattern
Instance methods
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/card/set_pattern.rb', line 68 def initialize card unless self.class.anchorless? @anchor_name = self.class.anchor_name(card).to_name @anchor_id = if self.class.respond_to? :anchor_id self.class.anchor_id card else Card.fetch_id @anchor_name end end self end |
Class Attribute Details
.anchorless ⇒ Object
Returns the value of attribute anchorless.
5 6 7 |
# File 'lib/card/set_pattern.rb', line 5 def anchorless @anchorless end |
.assigns_type ⇒ Object
Returns the value of attribute assigns_type.
5 6 7 |
# File 'lib/card/set_pattern.rb', line 5 def assigns_type @assigns_type end |
.junction_only ⇒ Object
Returns the value of attribute junction_only.
5 6 7 |
# File 'lib/card/set_pattern.rb', line 5 def junction_only @junction_only end |
.pattern_code ⇒ Object
Returns the value of attribute pattern_code.
5 6 7 |
# File 'lib/card/set_pattern.rb', line 5 def pattern_code @pattern_code end |
.pattern_id ⇒ Object
Returns the value of attribute pattern_id.
5 6 7 |
# File 'lib/card/set_pattern.rb', line 5 def pattern_id @pattern_id end |
Class Method Details
.anchorless? ⇒ Boolean
15 16 17 |
# File 'lib/card/set_pattern.rb', line 15 def anchorless? !!anchorless end |
.find(pattern_code) ⇒ Object
7 8 9 |
# File 'lib/card/set_pattern.rb', line 7 def find pattern_code Card.set_patterns.find { |sub| sub.pattern_code == pattern_code } end |
.junction_only? ⇒ Boolean
11 12 13 |
# File 'lib/card/set_pattern.rb', line 11 def junction_only? !!junction_only end |
.new(card) ⇒ Object
19 20 21 |
# File 'lib/card/set_pattern.rb', line 19 def new card super if pattern_applies? card end |
.pattern ⇒ Object
23 24 25 |
# File 'lib/card/set_pattern.rb', line 23 def pattern Card.fetch(self.pattern_id, :skip_modules=>true).cardname end |
.pattern_applies?(card) ⇒ Boolean
38 39 40 |
# File 'lib/card/set_pattern.rb', line 38 def pattern_applies? card junction_only? ? card.cardname.junction? : true end |
.register(pattern_code, opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/card/set_pattern.rb', line 27 def register pattern_code, opts={} if self.pattern_id = Card::Codename[pattern_code] self.pattern_code = pattern_code Card.set_patterns.insert opts.delete(:index).to_i, self self.anchorless = !respond_to?( :anchor_name ) opts.each { |key, val| send "#{key}=", val } else warn "no codename for pattern_code #{pattern_code}" end end |
.write_tmp_file(pattern_code, from_file, seq) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/card/set_pattern.rb', line 42 def write_tmp_file pattern_code, from_file, seq to_file = "#{Wagn.paths['tmp/set_pattern'].first}/#{seq}-#{pattern_code}.rb" klass = "Card::#{pattern_code.camelize}Set" file_content = "# -*- encoding : utf-8 -*-\nclass \#{klass} < Card::SetPattern\n cattr_accessor :options\n class << self\n# ~~~~~~~~~~~ above autogenerated; below pulled from \#{from_file} ~~~~~~~~~~~\n\n\#{ File.read from_file }\n\n# ~~~~~~~~~~~ below autogenerated; above pulled from \#{from_file} ~~~~~~~~~~~\n end\n register \"\#{pattern_code}\", (options || {})\nend\n\n" File.write to_file, file_content to_file end |
Instance Method Details
#anchor_codenames ⇒ Object
98 99 100 101 102 103 |
# File 'lib/card/set_pattern.rb', line 98 def anchor_codenames @anchor_name.parts.map do |part| part_id = Card.fetch_id part part_id && Card::Codename[ part_id.to_i ] or return nil end end |
#format_module_list(klass) ⇒ Object
94 95 96 |
# File 'lib/card/set_pattern.rb', line 94 def format_module_list klass module_key and hash = Card::Set.modules[ :nonbase_format ][ klass ] and hash[ module_key ] end |
#inspect ⇒ Object
113 114 115 |
# File 'lib/card/set_pattern.rb', line 113 def inspect "<#{self.class} #{to_s.to_name.inspect}>" end |
#module_key ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/card/set_pattern.rb', line 80 def module_key (defined? @module_key) ? @module_key : @module_key = begin if self.class.anchorless? self.class.pattern_code.camelize elsif anchor_codenames "#{self.class.pattern_code.camelize}::#{anchor_codenames.map(&:to_s).map(&:camelize) * '::'}" end end end |
#module_list ⇒ Object
90 91 92 |
# File 'lib/card/set_pattern.rb', line 90 def module_list module_key and Card::Set.modules[ :nonbase ][ module_key ] end |
#pattern ⇒ Object
105 106 107 |
# File 'lib/card/set_pattern.rb', line 105 def pattern @pattern ||= self.class.pattern end |
#rule_set_key ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/card/set_pattern.rb', line 122 def rule_set_key if self.class.anchorless? self.class.pattern_code elsif @anchor_id [ @anchor_id, self.class.pattern_code ].map( &:to_s ) * '+' end end |
#safe_key ⇒ Object
117 118 119 120 |
# File 'lib/card/set_pattern.rb', line 117 def safe_key caps_part = self.class.pattern_code.gsub(' ','_').upcase self.class.anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}" end |
#to_s ⇒ Object
109 110 111 |
# File 'lib/card/set_pattern.rb', line 109 def to_s self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}" end |