Class: GrubY::TDLib::SchemaBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gruubY/tdlib/schema_builder.rb

Constant Summary collapse

TL_DEF_REGEX =
/^(?<name>\w+)(?:#[0-9a-f]+)?\s+(?<params>.*)=\s+(?<type>\w+);$/
PARAM_DETAIL_REGEX =
/(?<name>\w+):(?<type>[^\s]+)/
ROW_REGEX =
/<tr>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<\/tr>/m
TAG_REGEX =
/<[^>]*>/

Instance Method Summary collapse

Constructor Details

#initialize(src:, version: "", commit: "", out: "tdlib.json") ⇒ SchemaBuilder

Returns a new instance of SchemaBuilder.



15
16
17
18
19
20
# File 'lib/gruubY/tdlib/schema_builder.rb', line 15

def initialize(src:, version: "", commit: "", out: "tdlib.json")
  @src = src
  @version = version
  @commit = commit
  @out = out
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gruubY/tdlib/schema_builder.rb', line 22

def call
  data = if @src.start_with?("http://", "https://")
           fetch_and_parse_tl(@src)
         else
           parse_tl_from_file(@src)
         end

  data["version"] = @version
  data["commit"] = @commit

  begin
    data["options"] = fetch_options
  rescue StandardError => e
    warn "Warning: failed to fetch options: #{e.message}"
  end

  save_json(data, @out)
end