Sha256: 216f83819dded46fc6a94262736b1e63cee548c21c8ac09064b35fa2104580df

Contents?: true

Size: 866 Bytes

Versions: 7

Compression:

Stored size: 866 Bytes

Contents

require 'json'

filename = 'account.json'
modelname = filename.split('.').first.capitalize

json = File.read( 'json/account.json' )
hash = JSON.parse( json )

header = <<-RB
require "fortnox/api/models/base"

module Fortnox
  module API
    module Entities
      module {{ model_name }}
        class Entity < Fortnox::API::Model::Base

RB

footer = <<-RB
        end
      end
    end
  end
end

RB

attribute = <<-RB
          # {{ description }}
          attribute :{{ name }}, {{ type }}

RB

generated_class = header.gsub( '{{ model_name }}', modelname )

hash.each do |name, attributes|
  generated_class << attribute.gsub( '{{ description }}', attributes.fetch( 'description' ) ).gsub( '{{ name }}', name ).gsub( '{{ type }}', attributes.fetch( 'type' ).capitalize )
end

generated_class << footer

File.write( "#{ modelname.downcase }.rb", generated_class )

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fortnox-api-0.5.2 docs/generation_script.rb
fortnox-api-0.5.1 docs/generation_script.rb
fortnox-api-0.5.0 docs/generation_script.rb
fortnox-api-0.4.0 docs/generation_script.rb
fortnox-api-0.3.0 docs/generation_script.rb
fortnox-api-0.2.0 docs/generation_script.rb
fortnox-api-0.1.0 docs/generation_script.rb