Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kputnam committed Sep 28, 2011
1 parent dae2d78 commit 8a2842b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/Serializing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Serializing X12
==============

Once you have built a parse tree, either by generating one programatically (see
{file:Generating.md Generating}) or parsing serialized input (see
{file:Parsing.md}), you can serialize it back to a string using one of the
classes in [`Stupidedi::Writer`][1].
Empty file.
Empty file.
63 changes: 63 additions & 0 deletions lib/stupidedi/editor/005010/N4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
class Stupidedi
module Editor

class FiftyTenEd
module N4

def critique_n4(n4, acc)
edit(:N4) do
usa_canada =
n4.element(2).select(&:present?).defined? ||
n4.element(4).select(&:blank?).defined? ||
n4.element(4).select{|e| e.node == "US" }.defined? ||
n4.element(7).select(&:blank?).defined?

# State or Province Code
n4.element(2).tap do |e|
if usa_canada
if e.node.blank? and e.node.situational?
# Required
end
else
if e.node.present? and e.node.situational?
# Forbidden
end
end
end

# Postal Code
n4.element(3).tap do |e|
if usa_canada and e.node =~ /^(\d{1,8}|\d{10,})$/
acc.warn(e, "must be 9-digits for usa")
end
end

# Country Code
n4.element(4).tap do |e|
if usa_canada
if e.node.present? and e.node.situational?
# Forbidden
end
else
# Country codes 2-digit from ISO 3166
end
end

# Country Subdivision Code
# n4.element(7).tap do |e|
# if usa_canada
# if e.node.present? and e.node.situational?
# # Forbidden
# end
# else
# # Country subdivision codes from ISO 3166
# end
# end
end
end

end
end

end
end
Empty file.
2 changes: 1 addition & 1 deletion notes/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
p z.root.node.characters.to_a

separators =
Stupidedi::Reader::Separators.build(:segment => "~\n", :element => "*")
Stupidedi::Reader::Separators.build(:segment => "~\n", :element => "*", :component => ">")

Stupidedi::Writer::Default.new(z.root, separators).write($stdout)
end

0 comments on commit 8a2842b

Please sign in to comment.