{"id":3239,"date":"2018-02-17T02:55:06","date_gmt":"2018-02-17T02:55:06","guid":{"rendered":"https:\/\/www.botreetechnologies.com\/blog\/?p=3239"},"modified":"2022-12-13T16:30:58","modified_gmt":"2022-12-13T11:00:58","slug":"compare-text-differences-between-two-contents-using-ruby-on-rails","status":"publish","type":"post","link":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/","title":{"rendered":"Compare Text Differences Between Two Contents (%) Using Ruby on Rails"},"content":{"rendered":"\n<p><i><b>Requirement:<\/b> Compare two contents (HTML, JavaScript code or any other text) and find text difference in percentage(%) between them.<\/i><\/p>\n\n\n\n<p><i><b>Technology:<\/b> Ruby on Rails<\/i><\/p>\n\n\n\n<p><i><b>Versions:<\/b> Rails: 5.1.4 , Ruby: 2.4.1 (would work with almost any version)<\/i><\/p>\n\n\n\n<p><i><b>Git Repo:<\/b> <a href=\"https:\/\/github.com\/AnkurVyas-BTC\/compare\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/AnkurVyas-BTC\/compare<\/a><\/i><\/p>\n\n\n\n<p>We are going to build something like below.<\/p>\n\n\n\n<h6 class=\"has-text-align-center wp-block-heading\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/Difference-Comparison.gif\" alt=\"Difference Comparison\" width=\"800\" height=\"508\">Difference Comparison (%)<\/h6>\n\n\n\n<p>For this we are going to use <a href=\"https:\/\/en.wikipedia.org\/wiki\/String_metric\" target=\"_blank\" rel=\"noreferrer noopener\">string metric<\/a> called as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Levenshtein_distance\" target=\"_blank\" rel=\"noreferrer noopener\">Levenshtein distance<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"304\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/virus-elaboration.jpeg\" alt=\"virus elaboration\" class=\"wp-image-13801\" srcset=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/virus-elaboration.jpeg 442w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/virus-elaboration-300x206.jpeg 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/figure>\n<\/div>\n\n\n<h6 class=\"has-text-align-center wp-block-heading\">PC: https:\/\/www.memecenter.com\/fun\/1057701\/virus-elaboration<\/h6>\n\n\n\n<p>Okay sir !!!<\/p>\n\n\n\n<p>In <a href=\"https:\/\/en.wikipedia.org\/wiki\/Information_theory\" target=\"_blank\" rel=\"noreferrer noopener\">information theory<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Linguistics\" target=\"_blank\" rel=\"noreferrer noopener\">Linguistics<\/a> and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Computer_science\" target=\"_blank\" rel=\"noreferrer noopener\">computer science<\/a>, the <b>Levenshtein distance<\/b> is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/String_metric\" target=\"_blank\" rel=\"noreferrer noopener\">string metric<\/a> for measuring the difference between two sequences. It is named after <a href=\"https:\/\/en.wikipedia.org\/wiki\/Vladimir_Levenshtein\" target=\"_blank\" rel=\"noreferrer noopener\">Vladimir Levenshtein<\/a>, who considered this distance in 1965.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><i>Informally, the Levenshtein distance between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other.<\/i><\/p><\/blockquote>\n\n\n\n<p>For this, we are going to use <a href=\"https:\/\/github.com\/threedaymonk\/text\" target=\"_blank\" rel=\"noreferrer noopener\">text<\/a> gem. Let&#8217;s start creating our app.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>$ rails new compare<\/code><\/p><\/blockquote>\n\n\n\n<p>This will create our rails app with name <i>compare<\/i>.<\/p>\n\n\n\n<p>Then move to our app directory and install the dependencies.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>$ bundle install<\/code><\/p><\/blockquote>\n\n\n\n<p>If above command gives you an error you may need install bundler gem for this.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>$ gem install bundler<\/code><\/p><\/blockquote>\n\n\n\n<p>Now your rails app is ready. Let&#8217;s add <i>text<\/i> gem to our app. Open <i>Gemfile<\/i> and write following line to add gem.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>gem 'text'<\/code><\/p><\/blockquote>\n\n\n\n<p>Again do <i><code>bundle install<\/code><\/i> to install the gem.<\/p>\n\n\n\n<p>Let&#8217;s create controller now by the following command.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>$ rails g controller comparisons compare<\/code><\/p><\/blockquote>\n\n\n\n<p>This will generate following files.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"327\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/comparison-controller-generation.png\" alt=\"comparison controller generation\" class=\"wp-image-13803\" srcset=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/comparison-controller-generation.png 770w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/comparison-controller-generation-300x127.png 300w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/comparison-controller-generation-768x326.png 768w\" sizes=\"auto, (max-width: 770px) 100vw, 770px\" \/><\/figure>\n<\/div>\n\n\n<h6 class=\"has-text-align-center wp-block-heading\">Output of comparison controller generation!<\/h6>\n\n\n\n<p>Add the routes at <i>config\/routes.rb<\/i><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>Rails.application.routes.draw do<\/code><\/p><p>get &#8216;comparisons\/compare&#8217;<\/p><p>post &#8216;comparisons\/compare_sections&#8217;<\/p><p>root to: &#8216;comparisons#compare&#8217;<\/p><p>end<\/p><\/blockquote>\n\n\n\n<p>Now go to <i><code>controllers\/comparisons_controller.rb<\/code><\/i> file and paste following contents.<\/p>\n\n\n\n<p><script src=\"https:\/\/gist.github.com\/AnkurVyas-BTC\/83b85ddbe5d67c90b0b55a4733d1b978.js\"><\/script><\/p>\n\n\n\n<h6 class=\"has-text-align-center wp-block-heading\">Gist for comparisons controller<\/h6>\n\n\n\n<p>Idea below (sample code run on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Interactive_Ruby_Shell\" target=\"_blank\" rel=\"noreferrer noopener\">irb console<\/a>)<\/p>\n\n\n\n<h6 class=\"has-text-align-center wp-block-heading\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/irb-code.png\" alt=\"irb code\" width=\"666\" height=\"40\">irb code<\/h6>\n\n\n\n<p>So from above the distance between <i>ankur<\/i> and <i>abkur<\/i> is 20% as there is <b>1<\/b> character change <b>out of 5<\/b>. This is exactly what we want.<\/p>\n\n\n\n<p>Leveraging the above functionality, the code is like below<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><code>distance = Text::Levenshtein.distance(params[:left_section], params[:right_section]).to_f<\/code><\/p><\/blockquote>\n\n\n\n<p>Here is the view file.<\/p>\n\n\n\n<p><script src=\"https:\/\/gist.github.com\/AnkurVyas-BTC\/247917190dc93a729b477d1171d88b36.js\"><\/script><\/p>\n\n\n\n<h6 class=\"has-text-align-center wp-block-heading\">app\/views\/comparisons\/compare.html.erb<\/h6>\n\n\n\n<p>Now as we have written <i>remote: true<\/i> in the form it would send an AJAX request. Following the the AJAX response code,<\/p>\n\n\n\n<p><script src=\"https:\/\/gist.github.com\/AnkurVyas-BTC\/1b6ce546a6b64dddcb01a276748c5b6b.js\"><\/script><\/p>\n\n\n\n<h6 class=\"has-text-align-center wp-block-heading\">app\/views\/comparisons\/compare_sections.js.erb<\/h6>\n\n\n\n<p>Result text shows in green when both contents are same and shows in red when contents are different!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"311\" height=\"42\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/Result-1.png\" alt=\"Result 1\" class=\"wp-image-13804\" srcset=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/Result-1.png 311w, https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/Result-1-300x41.png 300w\" sizes=\"auto, (max-width: 311px) 100vw, 311px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"271\" height=\"39\" src=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/12\/Result-2.png\" alt=\"result 2\" class=\"wp-image-13805\"\/><\/figure>\n\n\n\n<p>You can find the whole github code <a href=\"https:\/\/github.com\/AnkurVyas-BTC\/compare\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><i>Thanks for reading. If you liked it, press the clap &amp; share \ud83d\ude42<\/i><\/p><\/blockquote>\n\n\n\n<p><a href=\"https:\/\/www.botreetechnologies.com\/ruby-on-rails-development\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Click here for more details&#8230;<\/strong><\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>At <a href=\"https:\/\/www.botreetechnologies.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">BoTree Technologies<\/a>, we build enterprise applications with our RoR team of 25+ engineers.<\/p>\n\n\n\n<p>We also specialize in RPA, AI, Python, Django, JavaScript and ReactJS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.botreetechnologies.com\/contact\" target=\"_blank\" rel=\"noopener noreferrer\">Consulting is free<\/a> &#8211; let us help you grow!<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Requirement: Compare two contents (HTML, JavaScript code or any other&#8230;<\/p>\n","protected":false},"author":9,"featured_media":13797,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,10],"tags":[],"class_list":["post-3239","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails","category-technology"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Compare Text Differences Between Two Contents (%) Using Ruby on Rails<\/title>\n<meta name=\"description\" content=\"Compare two contents (HTML, JavaScript code or any other text) and find text difference in percentage(%) between them. Technology: Ruby on Rails.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Compare Text Differences Between Two Contents (%) Using Ruby on Rails\" \/>\n<meta property=\"og:description\" content=\"Compare two contents (HTML, JavaScript code or any other text) and find text difference in percentage(%) between them. Technology: Ruby on Rails.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/\" \/>\n<meta property=\"og:site_name\" content=\"BoTree Technologies\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BoTreeTechnologies\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-17T02:55:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-13T11:00:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1271\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ankur Vyas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:site\" content=\"@BoTreeTech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ankur Vyas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/\"},\"author\":{\"name\":\"Ankur Vyas\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5\"},\"headline\":\"Compare Text Differences Between Two Contents (%) Using Ruby on Rails\",\"datePublished\":\"2018-02-17T02:55:06+00:00\",\"dateModified\":\"2022-12-13T11:00:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/\"},\"wordCount\":425,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg\",\"articleSection\":[\"Ruby on Rails\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/\",\"name\":\"Compare Text Differences Between Two Contents (%) Using Ruby on Rails\",\"isPartOf\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg\",\"datePublished\":\"2018-02-17T02:55:06+00:00\",\"dateModified\":\"2022-12-13T11:00:58+00:00\",\"author\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5\"},\"description\":\"Compare two contents (HTML, JavaScript code or any other text) and find text difference in percentage(%) between them. Technology: Ruby on Rails.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#primaryimage\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg\",\"width\":1920,\"height\":1271,\"caption\":\"ruby compare strings\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.botreetechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Compare Text Differences Between Two Contents (%) Using Ruby on Rails\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#website\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/\",\"name\":\"BoTree Technologies\",\"description\":\"Committed to inspire generation.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5\",\"name\":\"Ankur Vyas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png\",\"url\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png\",\"contentUrl\":\"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png\",\"caption\":\"Ankur Vyas\"},\"description\":\"Ankur is a Ruby on Rails Developer and Practice Lead JavaScript. He loves Ruby, JavaScript, reading and writing blogs, problem-solving and taking ownership of work. Apart from coding he likes to listen to songs, gaming and traveling.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Compare Text Differences Between Two Contents (%) Using Ruby on Rails","description":"Compare two contents (HTML, JavaScript code or any other text) and find text difference in percentage(%) between them. Technology: Ruby on Rails.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/","og_locale":"en_US","og_type":"article","og_title":"Compare Text Differences Between Two Contents (%) Using Ruby on Rails","og_description":"Compare two contents (HTML, JavaScript code or any other text) and find text difference in percentage(%) between them. Technology: Ruby on Rails.","og_url":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/","og_site_name":"BoTree Technologies","article_publisher":"https:\/\/www.facebook.com\/BoTreeTechnologies\/","article_published_time":"2018-02-17T02:55:06+00:00","article_modified_time":"2022-12-13T11:00:58+00:00","og_image":[{"width":1920,"height":1271,"url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg","type":"image\/jpeg"}],"author":"Ankur Vyas","twitter_card":"summary_large_image","twitter_creator":"@BoTreeTech","twitter_site":"@BoTreeTech","twitter_misc":{"Written by":"Ankur Vyas","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#article","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/"},"author":{"name":"Ankur Vyas","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5"},"headline":"Compare Text Differences Between Two Contents (%) Using Ruby on Rails","datePublished":"2018-02-17T02:55:06+00:00","dateModified":"2022-12-13T11:00:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/"},"wordCount":425,"commentCount":0,"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg","articleSection":["Ruby on Rails","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/","url":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/","name":"Compare Text Differences Between Two Contents (%) Using Ruby on Rails","isPartOf":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#primaryimage"},"image":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#primaryimage"},"thumbnailUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg","datePublished":"2018-02-17T02:55:06+00:00","dateModified":"2022-12-13T11:00:58+00:00","author":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5"},"description":"Compare two contents (HTML, JavaScript code or any other text) and find text difference in percentage(%) between them. Technology: Ruby on Rails.","breadcrumb":{"@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#primaryimage","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2018\/02\/compare-text-differences-in-ruby-on-rails.jpeg","width":1920,"height":1271,"caption":"ruby compare strings"},{"@type":"BreadcrumbList","@id":"https:\/\/www.botreetechnologies.com\/blog\/compare-text-differences-between-two-contents-using-ruby-on-rails\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.botreetechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Compare Text Differences Between Two Contents (%) Using Ruby on Rails"}]},{"@type":"WebSite","@id":"https:\/\/www.botreetechnologies.com\/blog\/#website","url":"https:\/\/www.botreetechnologies.com\/blog\/","name":"BoTree Technologies","description":"Committed to inspire generation.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.botreetechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.botreetechnologies.com\/blog\/#\/schema\/person\/aa180b4d8d933949f15aba97d8d138a5","name":"Ankur Vyas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png","url":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png","contentUrl":"https:\/\/www.botreetechnologies.com\/blog\/wp-content\/uploads\/2020\/10\/ankur-vyas-1-150x150.png","caption":"Ankur Vyas"},"description":"Ankur is a Ruby on Rails Developer and Practice Lead JavaScript. He loves Ruby, JavaScript, reading and writing blogs, problem-solving and taking ownership of work. Apart from coding he likes to listen to songs, gaming and traveling."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=3239"}],"version-history":[{"count":4,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3239\/revisions"}],"predecessor-version":[{"id":18268,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/3239\/revisions\/18268"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media\/13797"}],"wp:attachment":[{"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=3239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=3239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.botreetechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=3239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}