Class: ODDB::Html::View::Drugs::DownloadList

Inherits:
List
  • Object
show all
Includes:
HtmlGrid::ErrorMessage
Defined in:
lib/oddb/html/view/drugs/downloads.rb

Constant Summary collapse

COMPONENTS =
{
  [0,0] => :name,
  [1,0] => :price_1,
  [2,0] => :price_12,
  [3,0] => :download_description,
  [4,0] => :download_example,
  [5,0] => :download_howto,
}
DEFAULT_HEAD_CLASS =
'groupheader'
STRIPED_BG =
true
SORT_HEADER =
false
EXTERNAL_DATADESCS =
{
  'compendium_de.oddb.org.firefox.epub' => 'http://www.openebook.org/specs.htm',
  'compendium_de.oddb.org.htc.prc' => 'http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen&File=mobiformat.htm',
  'compendium_de.oddb.org.kindle.mobi' => 'http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen&File=mobiformat.htm',
  'compendium_de.oddb.org.stanza.epub' => 'http://www.openebook.org/specs.htm',
  'patinfos_de.oddb.org.firefox.epub' => 'http://www.openebook.org/specs.htm',
  'patinfos_de.oddb.org.htc.prc' => 'http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen&File=mobiformat.htm',
  'patinfos_de.oddb.org.kindle.mobi' => 'http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen&File=mobiformat.htm',
  'patinfos_de.oddb.org.stanza.epub' => 'http://www.openebook.org/specs.htm',
}

Constants inherited from List

List::BACKGROUND_ROW, List::BACKGROUND_SUFFIX, List::LEGACY_INTERFACE, List::SORT_DEFAULT

Instance Method Summary collapse

Methods inherited from List

#query_args, #query_key, #sort_link

Instance Method Details

#download_description(model) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/oddb/html/view/drugs/downloads.rb', line 38

def download_description model
  link = HtmlGrid::Link.new :download_description, model, @session, self
  link.href = EXTERNAL_DATADESCS.fetch model.name do
    path = File.join 'datadesc', model.name + '.txt'
    @lookandfeel.resource_global(:downloads, path)
  end
  link
end

#download_example(model) ⇒ Object



46
47
48
49
50
51
# File 'lib/oddb/html/view/drugs/downloads.rb', line 46

def download_example model
  link = HtmlGrid::Link.new :download_example, model, @session, self
  path = File.join 'examples', model.name
  link.href = @lookandfeel.resource_global(:downloads, path)
  link
end

#download_howto(model) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/oddb/html/view/drugs/downloads.rb', line 52

def download_howto model
  if url = @lookandfeel.lookup("download_howto_url_#{model.name}")
    link = HtmlGrid::Link.new :download_howto, model, @session, self
    link.href = url
    link.value = @lookandfeel.lookup "download_howto_#{model.name}"
    link
  end
end

#initObject



34
35
36
37
# File 'lib/oddb/html/view/drugs/downloads.rb', line 34

def init
  super
  error_message
end

#name(model) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/oddb/html/view/drugs/downloads.rb', line 60

def name model
  size = model.size
  unit = 'B'
  units = %w{KB MB GB TB}
  while size > 1024 && unit = units.shift
    size = (size / 1024.0).ceil
  end
  name = "#{model.name} (~ #{size} #{unit})"
  box = HtmlGrid::InputCheckbox.new "downloads[#{model.name}]",
                                    model, @session, self
  [box, name]
end

#price_1(model) ⇒ Object



72
73
74
# File 'lib/oddb/html/view/drugs/downloads.rb', line 72

def price_1 model
  radio_price model, 1
end

#price_12(model) ⇒ Object



75
76
77
# File 'lib/oddb/html/view/drugs/downloads.rb', line 75

def price_12 model
  radio_price model, 12
end

#radio_price(model, months) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/oddb/html/view/drugs/downloads.rb', line 78

def radio_price model, months
  if price = model.price(months)
    radio = HtmlGrid::InputRadio.new "months[#{model.name}]",
                                     model, @session, self
    radio.value = months
    selected = @session.user_input(:months) || {}
    radio.set_attribute 'checked', months == (selected[model.name] || 1).to_i
    [radio, "EUR %4.2f" % price]
  end
end