Module: Phil

Defined in:
lib/phil.rb,
lib/phil/version.rb

Constant Summary collapse

VERSION =
'0.9.8'

Class Method Summary collapse

Class Method Details

.address(include_secondary = false) ⇒ Object



110
111
112
# File 'lib/phil.rb', line 110

def address(include_secondary = false)
  FFaker::Address.street_address(include_secondary)
end

.blockquote(paragraphs = nil) ⇒ Object



46
47
48
# File 'lib/phil.rb', line 46

def blockquote(paragraphs = nil)
  tag "blockquote", paragraphs
end

.cityObject



82
83
84
# File 'lib/phil.rb', line 82

def city
  FFaker::Address.city
end

.company_nameObject



106
107
108
# File 'lib/phil.rb', line 106

def company_name
  FFaker::Company.name
end

.currency(num, symbol = "$") ⇒ Object



58
59
60
61
# File 'lib/phil.rb', line 58

def currency(num, symbol = "$")
  val = ((pick(num) * 100) / 100).round(2) + pick(0..99).to_f / 100
  sprintf("$%.2f", val)
end

.date(day_window = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/phil.rb', line 71

def date(day_window = nil)
  now = Time.now.to_f
  if !day_window
    Time.at(now * rand)
  elsif day_window.respond_to?(:to_a)
    Time.at(now - pick(day_window) * 86400)
  else
    Time.at(now - rand * day_window * 86400)
  end
end

.domain_nameObject



86
87
88
# File 'lib/phil.rb', line 86

def domain_name
  FFaker::Internet.domain_name
end

.emailObject



90
91
92
# File 'lib/phil.rb', line 90

def email
  FFaker::Internet.email
end

.first_nameObject



94
95
96
# File 'lib/phil.rb', line 94

def first_name
  FFaker::Name.first_name
end

.image(*arguments) ⇒ Object



122
123
124
125
126
# File 'lib/phil.rb', line 122

def image(*arguments)
  opts = arguments.extract_options!
  opts = format_image_argument_output(opts.merge! parse_image_arguments(arguments))
  opts[:size] && "http://placehold.it/#{opts[:size]}#{opts[:color]}#{opts[:text]}"
end

.last_nameObject



98
99
100
# File 'lib/phil.rb', line 98

def last_name
  FFaker::Name.last_name
end


50
51
52
# File 'lib/phil.rb', line 50

def link_list(list_items = (3..10), item_length = (1..5))
  build_tag "ul", build_tags("li", -> { "<a href='#'>#{words(item_length)}</a>" }, list_items)
end

.loop(num) ⇒ Object



11
12
13
14
15
# File 'lib/phil.rb', line 11

def loop(num)
  pick(num).times do |i|
    yield(i)
  end
end

.markup(pattern = "h1 p p h2 p ol h2 p ul") ⇒ Object Also known as: body_content



54
55
56
# File 'lib/phil.rb', line 54

def markup(pattern="h1 p p h2 p ol h2 p ul")
  pattern.split(" ").map{ |t| tag(t) }.join.html_safe
end

.nameObject



102
103
104
# File 'lib/phil.rb', line 102

def name
  FFaker::Name.name
end

.number(length) ⇒ Object



63
64
65
# File 'lib/phil.rb', line 63

def number(length)
  (1..pick(length)).map { rand(10) }.join
end

.ol(list_items = nil, item_length = nil) ⇒ Object



42
43
44
# File 'lib/phil.rb', line 42

def ol(list_items = nil, item_length = nil)
  tag "ol", item_length, list_items
end

.paragraphs(num) ⇒ Object



33
34
35
36
# File 'lib/phil.rb', line 33

def paragraphs(num)
  content_method = -> { FFaker::Lorem.paragraphs(1).join }
  build_tags "p", content_method, pick(num)
end

.phone(format = "(###) ###-####") ⇒ Object



67
68
69
# File 'lib/phil.rb', line 67

def phone(format = "(###) ###-####")
  format.gsub(/#/) { rand(9) + 1 }
end

.pick(num) ⇒ Object



7
8
9
# File 'lib/phil.rb', line 7

def pick(num)
  num.respond_to?(:to_a) ? num.to_a.sample : num
end

.sometimes(num_or_content = 3, num = 3) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/phil.rb', line 17

def sometimes(num_or_content = 3, num = 3)
  if block_given?
    if num_or_content == pick(1..num_or_content)
      yield
    end
  else
    if num == pick(1..num)
      num_or_content
    end
  end
end

.stateObject



114
115
116
# File 'lib/phil.rb', line 114

def state
  FFaker::AddressUS.state
end

.state_abbrObject



118
119
120
# File 'lib/phil.rb', line 118

def state_abbr
  FFaker::AddressUS.state_abbr
end

.ul(list_items = nil, item_length = nil) ⇒ Object



38
39
40
# File 'lib/phil.rb', line 38

def ul(list_items = nil, item_length = nil)
  tag "ul", item_length, list_items
end

.words(num) ⇒ Object



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

def words(num)
  FFaker::Lorem.words(pick(num)).join(' ').html_safe
end