forked from digitalocean/kartograph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomains.rb
54 lines (43 loc) · 984 Bytes
/
domains.rb
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
require 'kartograph'
json = '{
"domains": [
{
"name": "example.com",
"ttl": 1800,
"zone_file": "Example zone file text..."
}
],
"meta": {
"total": 1
}
}'
class Domain
attr_accessor :name, :ttl, :zone_file
end
class MetaInformation
attr_accessor :total
end
class DomainMapper
include Kartograph::DSL
kartograph do
mapping Domain
root_key singular: 'domain', plural: 'domains', scopes: [:read]
property :name, scopes: [:read]
property :ttl, scopes: [:read]
property :zone_file, scopes: [:read]
end
end
class MetaInformationMapper
include Kartograph::DSL
kartograph do
mapping MetaInformation
root_key singular: 'meta', scopes: [:read]
property :total, scopes: [:read]
end
end
domains = DomainMapper.extract_collection(json, :read)
meta = MetaInformationMapper.extract_single(json, :read)
puts "Total Domains: #{domains.size}"
puts domains.map(&:name)
puts
puts "Total pages: #{meta.total}"