Sha256: 9505a89831dff52223bfd49fdc395937409c17ac437485e59ed07b136547c0d3

Contents?: true

Size: 614 Bytes

Versions: 7

Compression:

Stored size: 614 Bytes

Contents

require 'json'

types = JSON.load File.read 'types.json'
ans = types.map { |type, fields|
  max_length = fields.keys.map(&:length).max
  # haskell (ry
  # <<~EOF
  #   data #{type} = {
  #     #{fields.map { |field, attr|
  #       "#{"%-#{max_length}s" % field} :: #{attr['type'].inspect.delete('"')}"
  #     }.join("\n  ")}
  #   }
  # EOF
  <<~EOF
    #{type}
      #{fields.map { |field, attr|
        "#{attr['optional'] ? ' ' : '*'} #{"%-#{max_length}s" % field} #{attr['type'].inspect.delete('"')}"
      }.join("\n  ")}
  EOF
}.join("\n")
open 'types.txt', 'w' do |f| f.write ans end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tgbot-0.1.6 tools/gen_types_txt.rb
tgbot-0.1.5 tools/gen_types_txt.rb
tgbot-0.1.4 tools/gen_types_txt.rb
tgbot-0.1.3 tools/gen_types_txt.rb
tgbot-0.1.2 tools/gen_types_txt.rb
tgbot-0.1.1 tools/gen_types_txt.rb
tgbot-0.1.0 tools/gen_types_txt.rb