Module: LegalToMarkdown::JasonBuilder
- Defined in:
- lib/legal_markdown/legal_to_markdown/json_builder.rb
Instance Method Summary collapse
- #build_back_portion(content_hash) ⇒ Object
- #build_front_portion ⇒ Object
- #build_header_and_text_hashs(text_block) ⇒ Object
-
#build_jason ⇒ Object
this method will build a hash which we will use to build the structured JSON.
- #sha ⇒ Object
Instance Method Details
#build_back_portion(content_hash) ⇒ Object
76 77 78 79 |
# File 'lib/legal_markdown/legal_to_markdown/json_builder.rb', line 76 def build_back_portion( content_hash ) back_hash = content_hash.each_value.collect{|h| h["id"]} back_hash = { "content" => { "nodes" => back_hash } } end |
#build_front_portion ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/legal_markdown/legal_to_markdown/json_builder.rb', line 51 def build_front_portion document_hash = { "document" => { "title" => "", "abstract" => "", "views" => ["content"] }} if @docinfo.is_a?(Hash) document_hash = { "document" => document_hash['document'].merge(@docinfo) } end document_hash end |
#build_header_and_text_hashs(text_block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/legal_markdown/legal_to_markdown/json_builder.rb', line 59 def build_header_and_text_hashs( text_block ) text_block = text_block.split("\n").reject{|l| l == ""} text_block.inject({}) do |hash, line| h2 = {} if line[/^(\#+\s+)/] h2["id"]= "heading:" + sha h2["type"]= "heading" h2["data"]= { "content" => line.delete($1) } elsif line[/^\S/] h2["id"]= "text:" + sha h2["type"]= "text" h2["data"]= { "content" => line } end hash.merge( { h2["id"] => h2 } ) end end |
#build_jason ⇒ Object
this method will build a hash which we will use to build the structured JSON. roughly the hash / json will break down like this .… “id” “nodes”
"document"
"title" => ""
"abstract" => ""
"views" => ["content"]
"provision:SHA32"
"id" => "provision:SHA32"
"type" => "provision"
"data"
"level" => "level"
"provision_reference" => "assembled leader"
"provision_text" => "line - leader" #gaurd italics
"citation" => "citation"
"annotation:SHA32"
"id" => "annotation:SHA32"
"type" => "citation"
"data"
"pos" => [start_column, stop_column]
"citation_type" => "internal" | "external"
"cite_of" => #todo
"content" => "nodes" => ["provision:SHA32", ...]
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/legal_markdown/legal_to_markdown/json_builder.rb', line 31 def build_jason if @content.is_a?(Array) @content[0] = build_header_and_text_hashs @content[0] unless @content[0].empty? @content[2] = build_header_and_text_hashs @content[2] unless @content[2].empty? content_hash = {} content_hash = content_hash.merge(@content[0]) unless @content[0] || @content[0].empty? content_hash = content_hash.merge(@content[1]) content_hash = content_hash.merge(@content[2]) unless @content[2] || @content[2].empty? @content = content_hash else @content = build_header_and_text_hashs @content end back_hash = build_back_portion @content document_hash = build_front_portion.merge( @content ).merge( back_hash ); back_hash = {} @content = { "id" => sha, "nodes" => document_hash } end |
#sha ⇒ Object
81 82 83 |
# File 'lib/legal_markdown/legal_to_markdown/json_builder.rb', line 81 def sha return SecureRandom.hex end |