Class: HackCards::Card

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

Overview

This is class level documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

this is documentation for the initialize method



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

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

text, url, and image are readable and writable fields



12
13
14
# File 'lib/hack_cards.rb', line 12

def image
  @image
end

#textObject

text, url, and image are readable and writable fields



12
13
14
# File 'lib/hack_cards.rb', line 12

def text
  @text
end

#urlObject

text, url, and image are readable and writable fields



12
13
14
# File 'lib/hack_cards.rb', line 12

def url
  @url
end

Instance Method Details

#componentsObject



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

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

#displayObject



34
35
36
37
38
39
40
41
42
# File 'lib/hack_cards.rb', line 34

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



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

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

#text_url_partialObject



52
53
54
# File 'lib/hack_cards.rb', line 52

def text_url_partial
  # TODO text url partial
end

#typeObject



29
30
31
32
# File 'lib/hack_cards.rb', line 29

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

#url_partialObject



48
49
50
# File 'lib/hack_cards.rb', line 48

def url_partial
  # TODO url partial
end