Class: NotionRubyMapping::Mermaid
- Inherits:
-
Object
- Object
- NotionRubyMapping::Mermaid
- Defined in:
- lib/notion_ruby_mapping/controllers/mermaid.rb
Instance Attribute Summary collapse
-
#databases ⇒ Object
readonly
Returns the value of attribute databases.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #append_db_with_attributes(db_name) ⇒ Object
- #attach_database(db) ⇒ Object
- #count ⇒ Object
- #create_notion_db(target_page, inline) ⇒ Object
- #db_or_create(db_name) ⇒ Object
-
#initialize(full_text) ⇒ Mermaid
constructor
A new instance of Mermaid.
- #parse_text ⇒ Object
- #remain ⇒ Object
- #rename_reverse_name ⇒ Object
- #update_databases ⇒ Object
- #update_title ⇒ Object
Constructor Details
#initialize(full_text) ⇒ Mermaid
Returns a new instance of Mermaid.
6 7 8 9 10 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 6 def initialize(full_text) @lines = full_text.split "\n" @databases = Hash.new {} parse_text end |
Instance Attribute Details
#databases ⇒ Object (readonly)
Returns the value of attribute databases.
11 12 13 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 11 def databases @databases end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
11 12 13 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 11 def lines @lines end |
Instance Method Details
#append_db_with_attributes(db_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 31 def append_db_with_attributes(db_name) db = db_or_create db_name until @lines.empty? case @lines.shift when /^ *} *$/ break when /^ *Database +title +"(.*)" *$/ db.name = Regexp.last_match(1) when /^ *([^ ]+) +[^ ]+ +"(.*)" *$/ db.add_property Regexp.last_match(1), Regexp.last_match(2) when /^ *([^ ]+) +([^ ]+) *$/ db.add_property Regexp.last_match(1), Regexp.last_match(2) end end end |
#attach_database(db) ⇒ Object
47 48 49 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 47 def attach_database(db) @databases.values.select { |mdb| mdb.name == db.database_title.full_text }.first&.attach_database(db) end |
#count ⇒ Object
71 72 73 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 71 def count @databases.values.map(&:count).sum end |
#create_notion_db(target_page, inline) ⇒ Object
51 52 53 54 55 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 51 def create_notion_db(target_page, inline) @databases.each_value do |mdb| mdb.create_notion_db(target_page, inline) unless mdb.real_db end end |
#db_or_create(db_name) ⇒ Object
27 28 29 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 27 def db_or_create(db_name) @databases[db_name] ||= MermaidDatabase.new db_name end |
#parse_text ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 13 def parse_text return unless @lines.shift =~ /^erDiagram/ until @lines.empty? case @lines.shift when / *(\w+) *[|}][|o]--[o|][|{] *(\w+) *: *"(.*)" */ db_or_create(Regexp.last_match(1)).append_relation_queue db_or_create(Regexp.last_match(2)), Regexp.last_match(3) when / *(\w+) *{ */ append_db_with_attributes Regexp.last_match(1) end end end |
#remain ⇒ Object
75 76 77 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 75 def remain @databases.values.map(&:remain).sum end |
#rename_reverse_name ⇒ Object
67 68 69 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 67 def rename_reverse_name @databases.each_value(&:rename_reverse_name) end |
#update_databases ⇒ Object
63 64 65 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 63 def update_databases @databases.each_value(&:update_database) end |
#update_title ⇒ Object
57 58 59 60 61 |
# File 'lib/notion_ruby_mapping/controllers/mermaid.rb', line 57 def update_title @databases.each_value do |mdb| mdb.update_title end end |