-
Notifications
You must be signed in to change notification settings - Fork 3
/
commerce.go
60 lines (50 loc) · 1.41 KB
/
commerce.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package faker
import (
"fmt"
)
// Commercer Interface
type Commercer interface {
Color() string
Department() string
ProductName() string
Price(min, max int, s string) string
ProductAdjective() string
ProductMaterial() string
Product() string
}
// Commerce struct
type Commerce struct {
*Fake
}
// Color returns a commerce color
func (c *Commerce) Color() string {
return c.pick(commercePrefix + "/color")
}
// Department returns a commerce department
func (c *Commerce) Department() string {
return c.pick(commercePrefix + "/department")
}
// ProductName returns a commerce product name
func (c *Commerce) ProductName() string {
return fmt.Sprintf("%s %s %s", c.ProductAdjective(), c.ProductMaterial(), c.Product())
}
// ProductAdjective returns a commerce product adjective
func (c *Commerce) ProductAdjective() string {
return c.pick(commercePrefix + "/product_name/adjective")
}
// ProductMaterial returns a commerce product material
func (c *Commerce) ProductMaterial() string {
return c.pick(commercePrefix + "/product_name/material")
}
// Product returns a commerce product
func (c *Commerce) Product() string {
return c.pick(commercePrefix + "/product_name/product")
}
// Price returns a commerce price
func (c *Commerce) Price(min, max int, symbol string) string {
if min < 0 || max < 0 {
return fmt.Sprintf("%v%v", symbol, 0.0)
}
r := randomFloatRange(min, max)
return fmt.Sprintf("%v%.2f", symbol, r)
}