Class: HackCards::Card
- Inherits:
-
Object
- Object
- HackCards::Card
- Defined in:
- lib/hack_cards.rb
Instance Attribute Summary collapse
-
#image ⇒ Object
Returns the value of attribute image.
-
#text ⇒ Object
Returns the value of attribute text.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #components ⇒ Object
- #display ⇒ Object
-
#initialize(image: "", text: "", url: "") ⇒ Card
constructor
A new instance of Card.
- #text_partial ⇒ Object
- #text_url_partial ⇒ Object
- #type ⇒ Object
- #url_partial ⇒ Object
Constructor Details
#initialize(image: "", text: "", url: "") ⇒ Card
Returns a new instance of Card.
6 7 8 9 10 |
# File 'lib/hack_cards.rb', line 6 def initialize(image: "", text: "", url: "") @image = image if image.length > 0 @text = text if text.length > 0 @url = url if url.length > 0 end |
Instance Attribute Details
#image ⇒ Object
Returns the value of attribute image.
5 6 7 |
# File 'lib/hack_cards.rb', line 5 def image @image end |
#text ⇒ Object
Returns the value of attribute text.
5 6 7 |
# File 'lib/hack_cards.rb', line 5 def text @text end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/hack_cards.rb', line 5 def url @url end |
Instance Method Details
#components ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/hack_cards.rb', line 12 def components r = [] r << :image if image r << :text if text r << :url if url return r end |
#display ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/hack_cards.rb', line 25 def display if type == :text return text_partial elsif type == :url return url_partial elsif type == :text_url return text_url_partial end end |
#text_partial ⇒ Object
35 36 37 |
# File 'lib/hack_cards.rb', line 35 def text_partial "<p>#{text}</p>" end |
#text_url_partial ⇒ Object
43 44 45 |
# File 'lib/hack_cards.rb', line 43 def text_url_partial # TODO text url partial end |
#type ⇒ Object
20 21 22 23 |
# File 'lib/hack_cards.rb', line 20 def type string = components.reduce("") {|s, c| s + "_" + c.to_s} string[1..-1].to_sym end |
#url_partial ⇒ Object
39 40 41 |
# File 'lib/hack_cards.rb', line 39 def url_partial # TODO url partial end |