Class: ForgeryJa::Monetary

Inherits:
Forgery::Monetary
  • Object
show all
Defined in:
lib/forgery_ja/forgery_ja/monetary.rb

Overview

Extensions Forgery::Monetary

Class Method Summary collapse

Class Method Details

.formatted_money(options = {}) ⇒ Object

Returns String :max - :minの間の数値にを付与して返します.

Parameters:

  • Hash

    options

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :format (String) — default: "%d円"

    金額出力の際のフォーマット

  • :max (Fixnum) — default: 1000

    金額の最大値

  • :min (Fixnum) — default: 0

    金額の最小値

Returns:



9
10
11
12
# File 'lib/forgery_ja/forgery_ja/monetary.rb', line 9

def self.formatted_money(options={})
  options = {:format => "%d円"}.merge(options)
  options[:format] % money(options)
end

.money(options = {}) ⇒ Object

Create Random number

defaut 0 to 1000

Parameters:

  • Hash

    options

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :max (Fixnum) — default: 1000

    金額の最大値

  • :min (Fixnum) — default: 0

    金額の最小値

Returns:

  • Fixnum



20
21
22
23
24
25
# File 'lib/forgery_ja/forgery_ja/monetary.rb', line 20

def self.money(options={})
  options = {:max => 1000,
             :min => 0}.merge(options)

  (options[:min]..options[:max]).random
end

.popularity_money(options = {}) ⇒ Object

popularity in Japan

日本においてポピュラーな数値を生成します
適当実装ですので1980, 19800,などの数値になります

Parameters:

  • Hash

    options

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :digit (Fixnum) — default: 4

    金額の桁

Returns:

  • Fixnum



33
34
35
36
37
38
39
# File 'lib/forgery_ja/forgery_ja/monetary.rb', line 33

def self.popularity_money(options={})
  # TODO Popularityではない。適当過ぎる
  options = {:digit => 4}.merge(options)
  base_money = (1..9).random * (10 ** (options[:digit] - 1) )
  return base_money if options[:digit] < 3
  base_money + 98 * (10 ** (options[:digit] - 3))
end