Class: HackCards::Card

Inherits:
Object
  • Object
show all
Defined in:
lib/hack_cards.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image: "", text: "", url: "") ⇒ Card

Returns a new instance of Card.



8
9
10
11
12
# File 'lib/hack_cards.rb', line 8

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

#imageObject

Returns the value of attribute image.



6
7
8
# File 'lib/hack_cards.rb', line 6

def image
  @image
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/hack_cards.rb', line 6

def text
  @text
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/hack_cards.rb', line 6

def url
  @url
end

Instance Method Details

#componentsObject



14
15
16
17
18
19
20
# File 'lib/hack_cards.rb', line 14

def components
  r = []
  r << :image if image
  r << :text if text
  r << :url if url
  return r
end

#displayObject



27
28
29
30
31
32
33
34
35
# File 'lib/hack_cards.rb', line 27

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_partialObject



37
38
39
# File 'lib/hack_cards.rb', line 37

def text_partial
  "<p>#{text}</p>"
end

#text_url_partialObject



45
46
47
# File 'lib/hack_cards.rb', line 45

def text_url_partial
  # TODO text url partial
end

#typeObject



22
23
24
25
# File 'lib/hack_cards.rb', line 22

def type
  string = components.reduce("") {|s, c| s + "_" + c.to_s}
  string[1..-1].to_sym
end

#url_partialObject



41
42
43
# File 'lib/hack_cards.rb', line 41

def url_partial
  # TODO url partial
end