Module: Card::Set::Pattern::ClassMethods

Included in:
Base
Defined in:
lib/card/set/pattern/class_methods.rb

Overview

methods for Set::Pattern classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#anchor_parts_countObject



41
42
43
# File 'lib/card/set/pattern/class_methods.rb', line 41

def anchor_parts_count
  @anchor_parts_count ||= (anchorless? ? 0 : 1)
end

#anchorlessObject

Returns the value of attribute anchorless.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def anchorless
  @anchorless
end

#assigns_typeObject

Returns the value of attribute assigns_type.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def assigns_type
  @assigns_type
end

#junction_onlyObject

Returns the value of attribute junction_only.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def junction_only
  @junction_only
end

#pattern_codeObject

Returns the value of attribute pattern_code.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def pattern_code
  @pattern_code
end

#pattern_idObject

Returns the value of attribute pattern_id.



6
7
8
# File 'lib/card/set/pattern/class_methods.rb', line 6

def pattern_id
  @pattern_id
end

Instance Method Details

#anchorless?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/card/set/pattern/class_methods.rb', line 29

def anchorless?
  anchorless
end

#generic_labelObject

label for set pattern if no anchor is given



53
54
55
# File 'lib/card/set/pattern/class_methods.rb', line 53

def generic_label
  label nil
end

#junction_only?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/card/set/pattern/class_methods.rb', line 25

def junction_only?
  junction_only == true
end

#module_key(anchor_codes) ⇒ Object



45
46
47
48
49
50
# File 'lib/card/set/pattern/class_methods.rb', line 45

def module_key anchor_codes
  return pattern_code.to_s.camelize if anchorless?
  return unless anchor_codes # is this not an error?

  ([pattern_code] + anchor_codes).map { |code| code.to_s.camelize }.join "::"
end

#new(card) ⇒ Object



10
11
12
# File 'lib/card/set/pattern/class_methods.rb', line 10

def new card
  super if pattern_applies? card
end

#patternObject



33
34
35
# File 'lib/card/set/pattern/class_methods.rb', line 33

def pattern
  Card.fetch(pattern_id, skip_modules: true).name
end

#pattern_applies?(card) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/card/set/pattern/class_methods.rb', line 37

def pattern_applies? card
  junction_only? ? card.name.junction? : true
end

#register(pattern_code, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/card/set/pattern/class_methods.rb', line 14

def register pattern_code, opts={}
  if (self.pattern_id = Card::Codename.id(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