Module: Assert::Factory

Extended by:
Factory
Included in:
Factory
Defined in:
lib/assert/factory.rb

Defined Under Namespace

Modules: Random, TypeConverter

Constant Summary collapse

DAYS_IN_A_YEAR =
365
SECONDS_IN_DAY =
24 * 60 * 60

Instance Method Summary collapse

Instance Method Details

#binaryObject



73
74
75
# File 'lib/assert/factory.rb', line 73

def binary
  self.type_cast(Random.binary, :binary)
end

#booleanObject



77
78
79
# File 'lib/assert/factory.rb', line 77

def boolean
  self.type_cast(Random.integer.even?, :boolean)
end

#dateObject



20
21
22
23
# File 'lib/assert/factory.rb', line 20

def date
  @date ||= self.type_cast(Random.date_string, :date)
  @date + Random.integer(DAYS_IN_A_YEAR)
end

#datetimeObject



30
31
32
33
# File 'lib/assert/factory.rb', line 30

def datetime
  @datetime ||= self.type_cast(Random.datetime_string, :datetime)
  @datetime + (Random.float(DAYS_IN_A_YEAR) * SECONDS_IN_DAY).to_i
end

#dir_path(length = nil) ⇒ Object Also known as: path



55
56
57
# File 'lib/assert/factory.rb', line 55

def dir_path(length = nil)
  self.type_cast(Random.dir_path_string(length), :string)
end

#email(domain = nil, length = nil) ⇒ Object



69
70
71
# File 'lib/assert/factory.rb', line 69

def email(domain = nil, length = nil)
  self.type_cast(Random.email_string(domain, length), :string)
end

#file_name(length = nil) ⇒ Object



51
52
53
# File 'lib/assert/factory.rb', line 51

def file_name(length = nil)
  self.type_cast(Random.file_name_string(length), :string)
end

#file_pathObject



59
60
61
# File 'lib/assert/factory.rb', line 59

def file_path
  self.type_cast(Random.file_path_string, :string)
end

#float(max = nil) ⇒ Object



13
14
15
# File 'lib/assert/factory.rb', line 13

def float(max = nil)
  self.type_cast(Random.float(max), :float)
end

#hex(length = nil) ⇒ Object



47
48
49
# File 'lib/assert/factory.rb', line 47

def hex(length = nil)
  self.type_cast(Random.hex_string(length), :string)
end

#integer(max = nil) ⇒ Object



9
10
11
# File 'lib/assert/factory.rb', line 9

def integer(max = nil)
  self.type_cast(Random.integer(max), :integer)
end

#slug(length = nil) ⇒ Object



43
44
45
# File 'lib/assert/factory.rb', line 43

def slug(length = nil)
  self.type_cast(Random.slug_string(length), :string)
end

#string(length = nil) ⇒ Object



35
36
37
# File 'lib/assert/factory.rb', line 35

def string(length = nil)
  self.type_cast(Random.string(length), :string)
end

#text(length = nil) ⇒ Object



39
40
41
# File 'lib/assert/factory.rb', line 39

def text(length = nil)
  self.type_cast(Random.string(length || 20), :string)
end

#timeObject



25
26
27
28
# File 'lib/assert/factory.rb', line 25

def time
  @time ||= self.type_cast(Random.time_string, :time)
  @time + (Random.float(DAYS_IN_A_YEAR) * SECONDS_IN_DAY).to_i
end

#type_cast(value, type) ⇒ Object



81
82
83
# File 'lib/assert/factory.rb', line 81

def type_cast(value, type)
  self.type_converter.send(type, value)
end

#type_converterObject



85
# File 'lib/assert/factory.rb', line 85

def type_converter; TypeConverter; end

#url(host = nil, length = nil) ⇒ Object



65
66
67
# File 'lib/assert/factory.rb', line 65

def url(host = nil, length = nil)
  self.type_cast(Random.url_string(host, length), :string)
end