faussaire 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ require 'yaml'
2
+
3
+ module Faussaire
4
+ class Music
5
+ DATA_PATH = File.expand_path('../../../locale/fr.yml', __FILE__)
6
+
7
+ ##
8
+ # Fetches and samples data based on the provided key. If the fetched data is an array,
9
+ # it samples a single item, otherwise returns the data directly.
10
+ #
11
+ # @param key [String] The dot-separated key used to access the data.
12
+ # @return [Object, nil] The data fetched and optionally sampled.
13
+ #
14
+ def self.fetch(key)
15
+ data = YAML.load_file(DATA_PATH)
16
+ result = data.dig(*key.split('.'))
17
+ result.is_a?(Array) ? result.sample : result
18
+ end
19
+
20
+ ##
21
+ # Produces a random house song.
22
+ #
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # Faussaire::Music.house #=> "House is a feeling - LA Riots"
27
+ #
28
+ def self.house
29
+ fetch('fr.faussaire.music.house')
30
+ end
31
+
32
+ ##
33
+ # Produces a random French rap song.
34
+ #
35
+ # @return [String]
36
+ #
37
+ # @example
38
+ # Faussaire::Music.rap #=> "Onizuka - PNL"
39
+ #
40
+ def self.rap
41
+ fetch('fr.faussaire.music.rap')
42
+ end
43
+
44
+ ##
45
+ # Produces a random French variété song.
46
+ #
47
+ # @return [String]
48
+ #
49
+ # @example
50
+ # Faussaire::Music.variete #=> "Laisse tomber les filles - France Gall"
51
+ #
52
+ def self.variete
53
+ fetch('fr.faussaire.music.variete')
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,93 @@
1
+ require 'yaml'
2
+
3
+ module Faussaire
4
+ class Name
5
+ DATA_PATH = File.expand_path('../../locale/fr.yml', __dir__)
6
+
7
+ class << self
8
+ ##
9
+ # Initializes the data from the YAML file.
10
+ #
11
+ def initialize_data
12
+ @data = YAML.load_file(DATA_PATH)
13
+ end
14
+
15
+ ##
16
+ # Produces a random female first name.
17
+ #
18
+ # @return [String]
19
+ #
20
+ # @example
21
+ # Faussaire::Name.female_first_name #=> "Marie"
22
+ #
23
+ def female_first_name
24
+ key = 'fr.faussaire.name.female_first_name'
25
+ fetch(key)
26
+ end
27
+
28
+ ##
29
+ # Produces a random male first name.
30
+ #
31
+ # @return [String]
32
+ #
33
+ # @example
34
+ # Faussaire::Name.male_first_name #=> "Jean"
35
+ #
36
+ def male_first_name
37
+ key = 'fr.faussaire.name.male_first_name'
38
+ fetch(key)
39
+ end
40
+
41
+ ##
42
+ # Produces a random family name.
43
+ #
44
+ # @return [String]
45
+ #
46
+ # @example
47
+ # Faussaire::Name.family_name #=> "Dupont"
48
+ #
49
+ def family_name
50
+ key = 'fr.faussaire.name.family_name'
51
+ fetch(key)
52
+ end
53
+
54
+ ##
55
+ # Generates a full name by combining a random first name (either male or female) with a family name.
56
+ #
57
+ # @return [String]
58
+ #
59
+ # @example
60
+ # Faussaire::Name.name #=> "Marie Dupont"
61
+ #
62
+ def name
63
+ first_name = [female_first_name, male_first_name].sample
64
+ [first_name, family_name].join(' ')
65
+ end
66
+
67
+ private
68
+
69
+ ##
70
+ # Fetches and samples data based on the provided key.
71
+ # If the fetched data is an array, it samples a single item,
72
+ # otherwise returns the data directly.
73
+ #
74
+ # @param key [String] The dot-separated key used to access the data.
75
+ # @return [Object, nil] The data fetched and optionally sampled.
76
+ #
77
+ def fetch(key)
78
+ return nil if data.nil? || data.dig(*key.split('.')).nil?
79
+ data.dig(*key.split('.')).sample
80
+ end
81
+
82
+ ##
83
+ # Accessor for the data loaded from the YAML file.
84
+ # Ensures data is loaded only once and reused across method calls.
85
+ #
86
+ # @return [Hash]
87
+ #
88
+ def data
89
+ @data ||= initialize_data
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,173 @@
1
+ require 'yaml'
2
+
3
+ module Faussaire
4
+ class Tv
5
+ DATA_PATH = File.expand_path('../../../locale/fr.yml', __FILE__)
6
+
7
+ # Provides data related to the Festival de Cannes.
8
+ module FestivalCannes
9
+ class << self
10
+ ##
11
+ # Returns the total number of films presented at the festival.
12
+ #
13
+ # @return [Integer]
14
+ #
15
+ # @example
16
+ # Faussaire::Tv::FestivalCannes.total_films #=> 3200
17
+ #
18
+ def total_films
19
+ festival_cannes_data['total_films'].first
20
+ end
21
+
22
+ ##
23
+ # Produces a random country among the most represented at the festival.
24
+ #
25
+ # @return [String]
26
+ #
27
+ # @example
28
+ # Faussaire::Tv::FestivalCannes.most_represented_countries #=> "France"
29
+ #
30
+ def most_represented_countries
31
+ fetch('fr.faussaire.tv.festival_cannes.most_represented_countries')
32
+ end
33
+
34
+ ##
35
+ # Produces a random country from those that have won awards.
36
+ #
37
+ # @return [String]
38
+ #
39
+ # @example
40
+ # Faussaire::Tv::FestivalCannes.awarded_countries #=> "USA"
41
+ #
42
+ def awarded_countries
43
+ fetch('fr.faussaire.tv.festival_cannes.awarded_countries')
44
+ end
45
+
46
+ ##
47
+ # Produces a random director who has won the Palme d'Or twice.
48
+ #
49
+ # @return [String]
50
+ #
51
+ # @example
52
+ # Faussaire::Tv::FestivalCannes.directors_with_two_palms #=> "Quentin Tarantino"
53
+ #
54
+ def directors_with_two_palms
55
+ fetch('fr.faussaire.tv.festival_cannes.directors_with_two_palms')
56
+ end
57
+
58
+ ##
59
+ # Produces a random nominee who has received multiple awards.
60
+ #
61
+ # @return [String]
62
+ #
63
+ # @example
64
+ # Faussaire::Tv::FestivalCannes.multiple_awardises #=> "Meryl Streep"
65
+ #
66
+ def multiple_awardises
67
+ fetch('fr.faussaire.tv.festival_cannes.multiple_awardises')
68
+ end
69
+
70
+ ##
71
+ # Produces a random Palme d'Or winner.
72
+ #
73
+ # @return [String]
74
+ #
75
+ # @example
76
+ # Faussaire::Tv::FestivalCannes.winners #=> "Parasite"
77
+ #
78
+ def winners
79
+ fetch('fr.faussaire.tv.festival_cannes.winners')
80
+ end
81
+
82
+ ##
83
+ # Returns a random top box office figure from the festival's films.
84
+ #
85
+ # @return [String] The box office amount in USD.
86
+ #
87
+ # @example
88
+ # Faussaire::Tv::FestivalCannes.box_office #=> "$500 million"
89
+ #
90
+ def box_office
91
+ fetch('fr.faussaire.tv.festival_cannes.box_office')
92
+ end
93
+
94
+ private
95
+
96
+ def festival_cannes_data
97
+ fetch('fr.faussaire.tv.festival_cannes')
98
+ end
99
+
100
+ def fetch(key)
101
+ data = YAML.load_file(Faussaire::Tv::DATA_PATH)
102
+ result = data.dig(*key.split('.'))
103
+ result.is_a?(Array) ? result.sample : result
104
+ end
105
+ end
106
+ end
107
+
108
+ ##
109
+ # Fetches and samples data from the YAML file based on the provided key.
110
+ # If the data is an array, it samples a single item.
111
+ #
112
+ # @param key [String] The dot-separated key used to access the data.
113
+ # @return [Object, nil] The data fetched and optionally sampled.
114
+ #
115
+ def self.fetch(key)
116
+ data = YAML.load_file(DATA_PATH)
117
+ result = data.dig(*key.split('.'))
118
+ result.is_a?(Array) ? result.sample : result
119
+ end
120
+
121
+ def self.festival_cannes
122
+ FestivalCannes
123
+ end
124
+
125
+ ##
126
+ # Produces a random television show title.
127
+ #
128
+ # @return [String]
129
+ #
130
+ # @example
131
+ # Faussaire::Tv.show #=> "Game of Thrones"
132
+ #
133
+ def self.show
134
+ fetch('fr.faussaire.tv.show')
135
+ end
136
+
137
+ ##
138
+ # Produces a random famous influencer's name.
139
+ #
140
+ # @return [String]
141
+ #
142
+ # @example
143
+ # Faussaire::Tv.influencer #=> "Kim Kardashian"
144
+ #
145
+ def self.influencer
146
+ fetch('fr.faussaire.tv.influencer')
147
+ end
148
+
149
+ ##
150
+ # Produces a random famous couple from television.
151
+ #
152
+ # @return [String]
153
+ #
154
+ # @example
155
+ # Faussaire::Tv.famous_couples #=> "Ross and Rachel"
156
+ #
157
+ def self.famous_couples
158
+ fetch('fr.faussaire.tv.famous_couples')
159
+ end
160
+
161
+ ##
162
+ # Produces a random TV channel name.
163
+ #
164
+ # @return [String]
165
+ #
166
+ # @example
167
+ # Faussaire::Tv.channel #=> "HBO"
168
+ #
169
+ def self.channel
170
+ fetch('fr.faussaire.tv.channel')
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faussaire
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,108 @@
1
+ require 'yaml'
2
+
3
+ module Faussaire
4
+ class Wine
5
+ DATA_PATH = File.expand_path('../../locale/fr.yml', __dir__)
6
+
7
+ class << self
8
+ ##
9
+ # Produces a random wine name.
10
+ #
11
+ # @return [String]
12
+ #
13
+ # @example
14
+ # Faussaire::Wine.name #=> "Chateau Margaux"
15
+ #
16
+ def name
17
+ fetch('fr.faussaire.wine.name')
18
+ end
19
+
20
+ ##
21
+ # Produces a random wine type or style.
22
+ #
23
+ # @return [String]
24
+ #
25
+ # @example
26
+ # Faussaire::Wine.type #=> "Red Wine"
27
+ #
28
+ def type
29
+ fetch('fr.faussaire.wine.type')
30
+ end
31
+
32
+ ##
33
+ # Produces a random wine bottle type.
34
+ #
35
+ # @return [String]
36
+ #
37
+ # @example
38
+ # Faussaire::Wine.bottle_type #=> "Cabernet Sauvignon"
39
+ #
40
+ def bottle_type
41
+ fetch('fr.faussaire.wine.bottle_types')
42
+ end
43
+
44
+ ##
45
+ # Produces a random wine region.
46
+ #
47
+ # @return [String]
48
+ #
49
+ # @example
50
+ # Faussaire::Wine.region #=> "Bordeaux"
51
+ #
52
+ def region
53
+ fetch('fr.faussaire.wine.region')
54
+ end
55
+
56
+ ##
57
+ # Produces a random wine price with 99 cents and a Euro (€) symbol.
58
+ # Distribution:
59
+ # - 50% chance for a price between 3.5 and 499 (Low range)
60
+ # - 35% chance for a price between 499 and 2999 (Middle range)
61
+ # - 10% chance for a price between 3000 and 301300 (Upper-High range)
62
+ # - 15% chance for a price between 301301 and 482000 (Legendary range)
63
+ #
64
+ # @return [String]
65
+ #
66
+ # @example
67
+ # Faussaire::Wine.price #=> "39.99€"
68
+ #
69
+ def price
70
+ random_number = rand
71
+ euros = case random_number
72
+ when 0...0.5 then rand(3.5..499).floor
73
+ when 0.5...0.85 then rand(500..2999).floor
74
+ when 0.85...0.95 then rand(3000..301300).floor
75
+ else rand(301301..482000).floor
76
+ end
77
+ "#{euros}.99€"
78
+ end
79
+
80
+ ##
81
+ # Produces a random wine feature called "Licocorico".
82
+ #
83
+ # @return [String]
84
+ #
85
+ # @example
86
+ # Faussaire::Wine.licocorico #=> "Licocorico Special Blend"
87
+ #
88
+ def licocorico
89
+ fetch('fr.faussaire.wine.licocorico')
90
+ end
91
+
92
+ private
93
+
94
+ ##
95
+ # Fetches and samples data from the YAML file based on the provided key.
96
+ # If the data is an array, it samples a single item.
97
+ #
98
+ # @param key [String] The dot-separated key used to access the data.
99
+ # @return [Object, nil] The data fetched and optionally sampled.
100
+ #
101
+ def fetch(key)
102
+ data = YAML.load_file(DATA_PATH)
103
+ result = data.dig(*key.split('.'))
104
+ result.is_a?(Array) ? result.sample : result
105
+ end
106
+ end
107
+ end
108
+ end
data/lib/faussaire.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "faussaire/version"
4
+ require_relative "faussaire/base"
5
+ require_relative "faussaire/name"
6
+ require_relative 'faussaire/address'
7
+ require_relative 'faussaire/ancien'
8
+ require_relative 'faussaire/bizness'
9
+ require_relative 'faussaire/tv'
10
+ require_relative 'faussaire/wine'
11
+ require_relative 'faussaire/creamerie'
12
+ require_relative 'faussaire/gardinerie'
13
+ require_relative 'faussaire/citation'
14
+ require_relative 'faussaire/cosmos'
15
+ require_relative 'faussaire/music'
16
+
17
+
18
+ module Faussaire
19
+ class Error < StandardError; end
20
+
21
+ # Initialize data for the Faussaire gem
22
+ def self.initialize_data
23
+ Faussaire::Name.initialize_data
24
+ Faussaire::Address.initialize_data
25
+ # Add other modules' initialize_data methods if necessary
26
+ end
27
+
28
+ # Convenience method to initialize data for the entire Faussaire gem
29
+ initialize_data
30
+ end